Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webstorm Jasmine integration - JSHint does not recognize jasmine

I set up Jasmine integration in Webstorm 8.0.4 using File > Settings > JavaScript > Libraries. I added a karma-jasmine library with the lib/ folder of my karma-jasmine node module.

This works fine in a way that syntax highlighting works, I can jump to the declaration and the documentation is displayed correctly. So the connection seem to be fine. However, JSHint still complains for each keyword about it not being defined, e.g.

JSHint: 'describe' is not defined. (117)

See also the following screenshot. As you can see, the syntax highlighting is fine, but I still get an error.

webstorm jasmine integration JSHint

like image 580
dirkk Avatar asked Sep 29 '14 15:09

dirkk


2 Answers

Considering what I have from yeoman's build of my .jshintrc, yes you need to add these names to that file.

Annoying yes, unless you used something to scaffold with like, well, yeoman!

Here is the .jshintrc that yeoman creates for us - plus the addition of lodash/underscore and jQuery.

{
    "node": true,
    "browser": true,
    "esnext": true,
    "bitwise": true,
    "camelcase": true,
    "curly": true,
    "eqeqeq": true,
    "immed": true,
    "indent": 4,
    "latedef": true,
    "newcap": true,
    "noarg": true,
    "quotmark": "single",
    "undef": true,
    "unused": true,
    "strict": true,
    "trailing": true,
    "smarttabs": true,
    "multistr": true,
    "globals": {
        "after": false,
        "afterEach": false,
        "angular": false,
        "before": false,
        "beforeEach": false,
        "browser": false,
        "describe": false,
        "expect": false,
        "inject": false,
        "it": false,
        "jasmine": false,
        "spyOn": false,            
        "$": false,
        "_": false
    }
}
like image 97
Sten Muchow Avatar answered Sep 22 '22 05:09

Sten Muchow


It's a JSHint 'feature'. JSHint works on per-file basis and knows nothing about global variables and functions defined in other files unless they are added to 'global' list. This can be done by either adding the corresponding comments (/* global MY_LIB*/ - see http://www.jshint.com/docs/) in code, or by adding variables/functions you'd like to use globally to the 'Predefined' list in Preferences -> Javascript -> Code Quality Tool -> JSHint -> Predefined (,separated). It's the last item in the list of JSHint options

like image 41
lena Avatar answered Sep 21 '22 05:09

lena