Dušan Maďar
Dušan Maďar

Reputation: 9849

JSHint with Atom editor - ignore warnings

I am using the linter-jshint plugin for Atom editor.

I want to disable showing a couple of specific errors/warnings. For example: W003 - 'functionName' was used before it was defined..

Is it possible to specify an array of ignored errors/warnings somewhere in Atom's config.cson?

Basically I am asking if it's possible to do the same thing like in PyDev (Eclipse), where you can specify a list of errors/warnings to be ignored by pep8.

NOTE: I read the linter-jshint documentation but still don't know how to do this.

Upvotes: 1

Views: 4762

Answers (2)

Dušan Maďar
Dušan Maďar

Reputation: 9849

It can be done with .jshintrc.

You need to prefix the warning code with -, e.g. -W003, and use true/false to turn it off/on.

At the very bottom of my .jshintrc:

  ...

  // Ignored Warnings
  "-W003": true
}

Source: https://gist.github.com/amatiasq/db597053f0f891ff7abc

Upvotes: 4

Clifford Fajardo
Clifford Fajardo

Reputation: 1447

The linter-js-hint suggests you modify the config.cson file by editing ~/.atom/config.cson. However, I would take a different approach. If you don't have a .jshintrc at the root level of your directory, I would create one.

What is a .jshintrc file? It'a a configuration file with rules that tell JSHint which rules to enforce. JSHint will start looking for this file in the same directory as the file that's being linted. If not found, it will move one level up the directory tree all the way up to the filesystem root.

Here is a standard .jshintrc file you can copy-paste and modify to your needs.

I remember not too long ago, I had linter-jshint in Atom warning me that I had a few variables that weren't defined in a file like jQuery or Angular, so I simply added & disabled my configuration file.

Example: at the bottom of my .jshintrc I added angular to my list of globals.

{

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

In general, I think it's a great practice to have a .jshintrc or eslintrc file in your project so if another developer inherits your codebase, their code editor can automatically enforce the rules in your .jshintrc file.

Upvotes: 2

Related Questions