Turning off eslint rule for a specific line
To immediately disable an ESLint rule for a line, use // eslint-disable-next-line [rule-name]
:
Replace [rule-name]
with the exact rule to silence. If you leave out [rule-name]
, all rules will be disabled for that line.
Straight to the point: disabling rules
Disabling a rule for the next line
If you want to ignore ESLint just for the next line, use // eslint-disable-next-line [rule-name]
:
Deactivating multiple rules
If you wish to combine directives in a single comment to disable multiple rules, do this:
Ignoring a rule within a line
To disable rules within the line, employ // eslint-disable-line [rule-name]
:
Disabling rules for blocks of code
Wrap your code with /* eslint-disable */
and /* eslint-enable */
to temporarily turn off linting:
This also works to target specific rules:
Disabling a rule for the entire file
To pretend a rule doesn't exist in a file, use /* eslint rule-name:0 */
at the beginning:
Mastering rule management
Handling unique scenarios
ESLint also works with JSX. Just remember to adapt the standard line appropriately:
Document rule disabling
Always document why you’re disabling a rule. It helps the next person to read your code:
Avoid overuse
Disabling rules frequently might be an indicator of a more significant issue. It's like eating too much candy, you'll get a stomach ache. Refactor instead.
Thoughtful overrides
Thoughtful override, when required, improves code quality. Consider custom rules, third-party libraries, or coding styles:
Additional hints
Team decisions
In team coding, discuss when to disable rules. Mutually agreed standards reduce conflicts and maintain unified code quality.
Technical Debt
Use rule disabling as a temporary solution while addressing technical debt:
Emergencies and exceptions
A justified case for rule disabling is in emergencies:
Was this article helpful?