Inline Comments to Disable Rules
You'll learn how to selectively silence ESLint warnings when you have a legitimate reason to break a rule.
Why Suppress Linting Rules?
Sometimes you genuinely need to bend or break a linting rule—perhaps you're integrating third-party code, handling an edge case, or dealing with a framework requirement. ESLint provides special comments that tell the linter "I know what I'm doing here, skip this check."
Think of these comments like a "justified override" in a code review: you're acknowledging the deviation and taking responsibility for it.
The Inline Disable Comments
ESLint recognizes several comment formats:
Disable for the next line:
// eslint-disable-next-line no-console
console.log("Debugging output"); // Won't trigger no-console warning
Disable for the current line:
console.log("Debug"); // eslint-disable-line no-console
Disable for a block of code:
/* eslint-disable no-alert */
alert("Legacy code");
alert("More legacy code");
/* eslint-enable no-alert */
Disable multiple rules at once:
// eslint-disable-next-line no-console, no-alert
console.log(alert("Double override"));
Disable all rules (use sparingly!):
// eslint-disable-next-line
dangerousCode();
When to Use These
Use inline disables judiciously—they should be the exception, not the rule. Add them when you have a specific, documented reason why the normal rule doesn't apply. Overusing them defeats the purpose of linting.
Key Takeaway: ESLint inline comments let you suppress specific warnings where justified, giving you surgical control over rule enforcement without disabling rules globally.