Last updated: Apr 4, 2024
Reading timeยท4 min
You can disable multiple rules by separating them with a comma in a comment.
Suppose you have the following code.
let a = 5;
As shown in the screenshot multiple rules cause ESLint errors for the line of code.
Here is an example of disabling all 3 rules for the next line by separating them with a comma.
// eslint-disable-next-line unused-imports/no-unused-vars, prefer-const, @typescript-eslint/no-unused-vars let a = 5;
The example disables the following ESLint rules for the next line:
Notice that the comment starts with eslint-disable-next-line
.
The comment only applies to the next line so it has to be placed right above the code that causes the ESLint errors.
If you want to disable multiple ESLint rules for the current line, place the comment on the line that causes the errors and separate the rules by a comma.
let a = 5; // eslint-disable-line unused-imports/no-unused-vars, prefer-const, @typescript-eslint/no-unused-vars
The comment must be placed on the same line as the code that causes the ESLint
errors and must start with eslint-disable-line
.
If you need to disable multiple ESLint rules for multiple lines (a code block), use a multiline comment and separate the rules with a comma.
/* eslint-disable unused-imports/no-unused-vars, prefer-const, @typescript-eslint/no-unused-vars */ let a = 5; let b = 10; /* eslint-enable unused-imports/no-unused-vars, prefer-const, @typescript-eslint/no-unused-vars */ // ๐๏ธ rules are no longer disabled here
The example disables the following rules for the block of code:
Notice that we used multiline comments (/* */
) and not inline comments (//
).
The first multiline comment should start with eslint-disable
and the second
multiline comment should start with eslint-enable
.
The ESLint rules are enabled after the second comment.
The same approach can be used to disable a single ESLint rule for multiple lines.
/* eslint-disable unused-imports/no-unused-vars */ let a = 5; let b = 10; /* eslint-enable unused-imports/no-unused-vars */ // ๐๏ธ rule is no longer disabled here
The example above disables the unused-imports/no-unused-vars
rule for a block
of code.
The same approach can be used if you need to disable multiple ESLint rules for an entire file.
Add an eslint-disable
command at the top of the file and specify the ESLint
rules you want to disable separated by commas.
/* eslint-disable unused-imports/no-unused-vars, prefer-const, @typescript-eslint/no-unused-vars */ let a = 5; let b = 10;
The comment should start with eslint-disable
.
Notice that the rules are separated by commas.
We didn't add an eslint-enable
comment at the end of the code block, so the
rules are disabled for the entire file.
The same approach is used if you want to disable a single ESLint rule for an entire file
/* eslint-disable unused-imports/no-unused-vars */ let a = 5; let b = 10;
The comment disables the unused-imports/no-unused-vars
ESLint rule for the
entire file.
If you need to disable all ESLint rules for a block of code, use the
eslint-disable
and eslint-enable
multiline comments.
/* eslint-disable */ let a = 5; let b = 10; /* eslint-enable */ // ๐๏ธ ESLint rules are enabled here
When you use an eslint-disable
comment without specifying rules, then all
ESLint rules are disabled.
The eslint-enable
comment enables the ESLint rules.
You can also use a comment if you want to disable all ESLint rules for an entire file.
/* eslint-disable */ let a = 5; let b = 10;
Notice that we didn't use an eslint-enable
comment, so the disable
rule
applies to the entire file.
Make sure to add the rule at the top of your file.
.eslintrc
file globallyTo disable multiple ESLint rules globally in your ESLint config file, specify
the rules in the rules
object and set them to off
.
If you use a .js
config file (.eslintrc.js
), use the following syntax to
disable multiple rules.
module.exports = { rules: { "unused-imports/no-unused-vars": "off", "@typescript-eslint/no-unused-vars": "off", "prefer-const": "off" }, };
Notice that the name of each rule is set as a property in the rules
object and
the value is set to off
to disable the rule globally.
If you use a JSON ESLint config (.eslintrc
or .eslintrc.json
), use the
following syntax instead.
{ "rules": { "unused-imports/no-unused-vars": "off", "@typescript-eslint/no-unused-vars": "off", "prefer-const": "off" } }
Notice that each string property and value must be double-quoted.
Make sure you don't have a trailing comma if you manage your ESLint config using JSON.
You can learn more about the related topics by checking out the following tutorials: