Disabling the eslint rule for a specific file

Is it possible to disable the eslint rule for an entire file? Something like:

// eslint-disable-file no-use-before-define 

(Similar to eslint-disable-line.) It happens to me quite often that in a certain file I break a certain rule in many places that are considered OK for this file, but I don’t want to disable the rule for the whole project, and I don’t want disable other rules for this particular file.

+307
javascript configuration lint eslint
Jan 13 '16 at 10:31
source share
11 answers

You can disable / change a specific rule for a file by placing configurations at the top of the file.

 /* eslint no-use-before-define: 0 */ // --> OFF or /* eslint no-use-before-define: 2 */ // --> ON 

Additional information: http://eslint.org/docs/user-guide/configuring.html#configuring-rules

+334
Jan 13 '16 at 16:05
source share

Just put /* eslint-disable */ at the top of the file

Check out: https://evanhahn.com/disable-eslint-for-a-file/

+193
Oct. 16 '16 at 11:29
source share

You can tell ESLint to ignore specific files and directories by creating a .eslintignore file in the project root directory:

.eslintignore

 build/*.js config/*.js bower_components/foo/*.js 

Ignore models behave according to the .gitignore specification. (Remember to restart the editor.)

+104
Dec 12 '16 at 21:57
source share

You can also disable / enable a rule like this:

 /* eslint-disable no-use-before-define */ ... code that violates rule ... /* eslint-enable no-use-before-define */ 

Similar to eslint-disable-line , as mentioned in the question. This may be the best method if you do not want to restore a complex rule configuration when you re-enable it.

+92
Jan 14 '16 at 21:45
source share

To temporarily disable rule warnings in your file, use block comments in the following format:

 /* eslint-disable */ 

This will disable ESLint before

 /* eslint-enable */ 

comment reached.

You can read more about this topic here .

+43
Aug 11 '17 at 1:07 on
source share

The accepted answer did not work for me (maybe another version of eslint ...? I am using eslint v3.19.0 ), but found a solution with the following ...

At the top of the file, place the following:

/* eslint-disable no-use-before-define */

This will disable the rule for the entire file.

+32
Aug 18 '17 at 17:34 on
source share

It is better to add "overrides" to your .eslintrc.js configuration file. For example, if you want to disable the camelcase rule for all js files ending in Actions, add this code after the rules scope in .eslintrc.js.

 "rules": { ........... }, "overrides": [ { "files": ["*Actions.js"], "rules": { "camelcase": "off" } } ] 
+19
Mar 15 '19 at 13:56
source share

Summarize:

Case 1: You want to disable All Rules for Single File

Place the comment /* eslint-disable */ at the top of the file.

Case 2: You want to disable All Rules for Some Files

There are 3 ways to do this:

  1. You can /* eslint-disable */ solve for case 1 and add /* eslint-disable */ over the files, one by one.
  2. You can put file names in .eslintignore . This works well if you have a path that you want to ignore. (e.g. apidoc/** )
  3. Alternatively, if you do not want to have a separate .eslintignore file, you can add "eslintIgnore": ["file1.js", "file2.js"] in package.json as indicated here .

Case 3: You want to disable "Some rules" for "Single file"

Place /* eslint-disable no-use-before-define */ comment at the top of the file. More examples here .

Case 4: You want to disable "Some rules" for "Some files"

It is less simple. You must put them in the "excludedFiles" object of the "overrides" section of your .eslintrc , as indicated here .

+16
Jun 22 '19 at 23:40
source share
 /*eslint-disable */ //suppress all warnings between comments alert('foo'); /*eslint-enable */ 

it worked for me

+8
Sep 19 '16 at 20:04
source share

You can simply put this, for example, at the top of the file:

 /* eslint-disable no-console */ 
+4
Feb 15 '19 at 7:55
source share

You can disable a specific rule for a file using /*eslint [<rule: "off"], >]*/

/* eslint no-console: "off", no-mixed-operators: "off" */

Version: eslint@4.3.0

0
Nov 30 '18 at 0:19
source share



All Articles