Is it possible to turn off the eslint rule for the whole file? Something such as:
// eslint-disable-file no-use-before-define
(Analogous t
To disable specific rules for file(s) inside folder(s), you need to use the "overrides"
key of your .eslintrc
config file.
For example, if you want to remove the following rules:
max-lines-per-function
import/no-unresolved
For all files inside the following main folder:
/spec
You can add this to your .eslintrc
file...
"overrides": [
{
"files": ["spec/**/*.js"],
"rules": {
"max-lines-per-function": ["off"],
"import/no-unresolved": ["off"]
}
}
]
Note that I used **
inside the spec/**/*.js
regex, which means I am looking recursively for all subfolders inside the folder called spec
and selecting all files that ends with js
in order to remove the desired rules from them.
To disable a specific rule for the file:
/* eslint-disable no-use-before-define */
Note there is a bug in eslint where single line comment will not work -
// eslint-disable max-classes-per-file
// This fails!
Check this post
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"
}
}
]
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.
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.
You can just put this for example at the top of the file:
/* eslint-disable no-console */