How to tell JSLint / JSHint what global variables are already defined

Emiliano Zilocchi picture Emiliano Zilocchi · Jul 17, 2013 · Viewed 41.2k times · Source

In my project we have some global variables that work as containers:

MyProject.MyFreature.someFunction = function() { ... }

So then I use that script across the site and JSLint / JSHint complains about that:

'MyProject' is not defined

I know that I can go to every JavaScript file and add the comment /*global MyProject*/ on top of it. But I'm looking a way to define that comment in some sort of config file so I don't have to go file by file adding this comment.

Some kind on option in the config/jshint.yml would be nice.

Answer

Epeli picture Epeli · Jul 17, 2013

For JSHint you can create .jshintrc to your project directory with

{
  "globals": { "MyProject": true }
}