JSHint with Atom editor

According to the documentation (note that this information is based on an older version but is still relevant), it is not explicitly stated, but you can use multiple jslint comments to enable or disable various checks in the code, thanks to Dominic Mitchell.
Query:
JSHint is flagging an issue on this particular line of code.
The issues are related to an unresolved variable ‘is’ and an unresolved function ‘is’.

Question:

I’m utilizing the

linter-jshint

plugin with the

Atom

editor.

I would like to deactivate the display of certain errors and warnings, such as

W003 - 'functionName' was used before it was defined.

.

Is there a way to define a collection of errors/warnings to be ignored in Atom’s

config.cson

?

I am inquiring about the possibility of achieving a similar functionality to

PyDev

(

Eclipse

), wherein it is feasible to define a set of errors/warnings to be excluded by

pep8

.

I have gone through the documentation for

linter-jshint

, but I am still unsure about how to accomplish this.


Solution 1:

The task can be accomplished using

.jshintrc

.

The warning code should be preceded by

-

, for example,

-W003

, and

true/false

should be used to enable/disable it.

Deep within my

.jshintrc

:
“””.

  ...
  // Ignored Warnings
  "-W003": true
}

The original source can be found at the following link: https://gist.github.com/amatiasq/db597053f0f891ff7abc.


Solution 2:


The linter-js-hint recommends making changes to the file

config.cson

by editing

~/.atom/config.cson

. However, my suggestion would be to create a

.jshintrc

at the root level of your directory if one does not already exist.

A ”

.jshintrc

” file is a configuration file containing rules that instruct JSHint on which rules to enforce. JSHint will search for this file starting from the same directory as the file being linted. If not found, it will move up the directory tree until it reaches the root of the filesystem.

You can copy and paste this standard

.jshintrc

file and make modifications according to your requirements.

Not too long ago, I recall receiving a warning from linter-jshint in Atom about undefined variables in a file such as jQuery or Angular. To resolve this, I promptly added and disabled my configuration file.

In my

.jshintrc

, I included angular as one of the global variables.

{
  "jquery": false,
   //.....more rules..
   // Custom Globals
   "globals": {        // additional predefined global variables
      "angular": false
    }
}

Overall, I believe it is beneficial to include a

.jshintrc

or

eslintrc

file in your project. This way, if another developer takes over your codebase, their code editor can automatically apply the rules from your

.jshintrc

file.

Frequently Asked Questions