Selectively disable ESLint
You can disable ESLint for a single line, a block of code, or an entire file. Wherever possible, specify the rule or rules you wish to disable.
Disable ESLint for a single line
Use the eslint-disable-line
and eslint-disable-next-line
directives to disable linting for a specific line.
const bad_string = 'nope' // eslint-disable-line camelcase
// eslint-disable-next-line no-array-constructor
const badArray = Array(100)
Disable ESLint for a block
Use the eslint-disable
and eslint-enable
directives to disable linting for a block of code.
/* eslint-disable no-await-in-loop, no-console */
for (const count = 0; count < 10; count++) {
console.log(`Processing ${count}`)
await doThing(count)
}
/* eslint-enable no-await-in-loop, no-console */
Disable ESLint for an entire file
There are several ways to disable linting for an entire file.
Use a block directive
The simplest option is to place a block directive at the start of the file.
/* eslint-disable complexity */
function theHorror(x) {
if (true) {
return x
} else if (false) {
return x + 1
} else {
return x + 2
}
}
Use an “ignore” file
Create a .eslintignore
file in the root of your project containing the files to ignore, one per line. ESLint supports .gitignore
-style patterns, exclusions, and so forth.
build/*.js
!build/special.js
Note that this disables all rules for the specified files.
Use a configuration file
ESLint supports an absurd array of configuration files. To further complicate matters you can place these files in nested directories, causing the configuration to cascade. Don’t do that.
Sign up for my newsletter
A monthly round-up of blog posts, projects, and internet oddments.