Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell JSHint to ignore all undefined variables in one file?

In Karma tests, there are a lot of global variables and functions, which JSHint complains about (it is integrated into my editor).

How can I tell JSHint to ignore all undefined variables in this one specific file? I would expect /* jshint undef: false */ to turn off these warning, but it doesn't.

like image 207
Dan Ross Avatar asked Jun 28 '13 07:06

Dan Ross


People also ask

How do I ignore JSHint warning?

In October 2013 jshint added a way to ignore blocks of code like this: // Code here will be linted with JSHint. /* jshint ignore:start */ // Code here will be ignored by JSHint. /* jshint ignore:end */ // Code here will be linted with JSHint.

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.

What does JSHint do?

JSHint is a static analysis tool written in JavaScript that helps developers detect potential bugs in their JavaScript code and enforce their development team's JavaScript coding conventions. JSHint scans your program's source code and reports about commonly made mistakes and potential bugs.


2 Answers

The correct way to tell JSHint about globals is to use the globals directive. For example:

/*globals globalFunction, anotherGlobal, oneMore */ 

This will prevent "{a} is not defined" warnings when JSHint encounters any of the listed identifiers.

Alternatively, if you really want to ignore all "not defined" warnings in that file, and you're using JSHint 1.0.0 or above, you can simply turn off that specific warning:

/*jshint -W117 */ 
like image 197
James Allardice Avatar answered Sep 21 '22 23:09

James Allardice


Just add this rule in your .jshintrc file.

"-W117": true 

This will ignore all the warnings which say, '* is not defined.'

like image 35
Balasubramani M Avatar answered Sep 20 '22 23:09

Balasubramani M