Turning off eslint rule for a specific file

a 夏天 提交于 2019-11-27 16:53:57

You can turn off/change a particular rule for a file by putting the configurations at the top of the file.

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

or

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

More info: http://eslint.org/docs/user-guide/configuring.html#configuring-rules

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

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

You can tell ESLint to ignore specific files and directories by creating an .eslintignore file in your project’s root directory:

.eslintignore

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

The ignore patterns behave according to the .gitignore specification. (Don't forget to restart your editor.)

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. It might be a better method if you don't want to have to restore a complicated rule configuration when re-enabling it.

luswata samuel

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

/* eslint-disable */

This will disable ESLint until the

/* eslint-enable */

comment is reached.

You can read more about this topic here.

Accepted answer didn't work for me (maybe a different version of eslint...? I'm using eslint v3.19.0), but did find a solution with the following...

Place the following on the top of your file

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

This will disable the rule for the entire file

It's better to add "overrides" in your .eslintrc.js config file. For example if you wont to disable camelcase rule for all js files ending on Actions add this code after rules scope in .eslintrc.js.

"rules": {    
...........    
},
"overrides": [
 {
  "files": ["*Actions.js"],
     "rules": {
        "camelcase": "off"   
     }
 }
]

To summarize:

Case 1: You want to disable "All Rules" for "One File"

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

Case 2: You want to disable "All rules" for "Some Files"

There are 3 ways you can do this:

  1. You can go with Case 1 solution and add /* eslint-disable */ on top of the files, one by one.
  2. You can put the file name(s) in .eslintignore. This works well if you have a path that you want to be ignored. (e.g. apidoc/**)
  3. Alternatively, if you don't want to have a separate .eslintignore file, you can add "eslintIgnore": ["file1.js", "file2.js"] in package.json as instructed here.

Case 3: You want to disable "Some rules" for "One File"

Put the /* 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"

This is less straight-forward. You should put them in "excludedFiles" object of "overrides" section of your .eslintrc as instructed here.

/*eslint-disable */

//suppress all warnings between comments
alert('foo');

/*eslint-enable */

it worked for me

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

/* eslint-disable no-console */

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

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

Version: eslint@4.3.0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!