ESLint is fully configurable, so you are able to turn off linting rules.
There are two ways for disabling rules: you can tell ESLint to do this from a Javascript comment or from a configuration file.
How to turn off an ESLint rule from the .eslintrc config file
To disable specific rules from the .eslintrc file you have to add a “rules” section. For example, if you want to turn the no-var
off, you have to add to the .eslintrc file the following lines
1 2 3 4 5 |
{ "rules": { "no-var": off } } |
How to disable ESLint on a specific line for a specific rule with a Javascript comment
You can disable ESLint on a specific line of a file
1 |
alert("hello"); // eslint-disable-line |
If you don’t like having the comment on the same line you can disable ESLint for the next line, this way
1 2 |
// eslint-disable-next-line alert("eslint is disabled here"); |
And you can disable only a specific rule on the line.
Here we disable the no-alert rule.
1 |
alert("hello"); // eslint-disable-line no-alert |
How to disable ESLint for a whole file with a Javascript comment
You can disable ESLint for a whole file by using the following Javascript comment
1 |
/* eslint-disable */ |
You can then re-enable ESlint with
1 |
/* eslint-enable */ |
This method is usefull also to disable linting on a piece of code, like:
1 2 3 4 5 |
/* eslint-disable */ alert("no linting here"); /* eslint-enable */ |
References
You can find further details here: https://eslint.org/docs/user-guide/configuring#configuring-rules