Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 525
Emiliano Zilocchi Avatar asked Jul 17 '13 20:07

Emiliano Zilocchi


People also ask

Is JSHint deprecated?

Warning This option has been deprecated and will be removed in the next major release of JSHint. JSHint is limiting its scope to issues of code correctness. If you would like to enforce rules relating to code style, check out the JSCS project.

Was used before it was defined JSLint?

The "'{a}' was used before it was defined" error (and the alternative "'{a}' is not defined" error) is thrown when JSLint, JSHint and ESLint encounter an identifier that has not been previously declared in a var statement or function declaration.

Should I use JSLint?

Use JSLint if you're looking for a very high standard for yourself or your team, but bear in mind that it's not necessarily the standard, only a standard, some of which comes to us dogmatically from Doug Crockford.


1 Answers

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

{   "globals": { "MyProject": true } } 
like image 52
Epeli Avatar answered Oct 12 '22 16:10

Epeli