Funonly
Funonly

Reputation: 283

How to set the scope for defined variables in another file for JSHint in WebStorm?

How can I set the scope of the defined variables for JSHint to my whole project in WebStorm?

If I have multiple files and imports like jquery or Backbone I don't need to see the error JSHint: 'Backbone' is not defined.(W117). This is not only form my imported libraries, but also for my own external files.

Some suggestions is that I should disable undefined errors, but this is the functionality that I want to use.

I.E.
In my main.js I have this:

function Main(){
    // Some epic code
}

Main.prototype.theBestFunctionEver = function(awesome, stuff){
    return awesome + stuff;
}

and in foo.js I have this:

function init(){
    var main = new Main(); // Shows that Main is undefined
    var wrongVar = 6 + unInited // This should always give me an error
    // Rest of init
}

Upvotes: 6

Views: 951

Answers (1)

Funonly
Funonly

Reputation: 283

JSHint works on per-file basis and doesn't 'see' variables 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).

Upvotes: 2

Related Questions