skip to content

With ESLint 10, what does linterOptions.reportUnusedDisableDirectives report, what is its default, and what changes when you set it to "error"?

level: middleimportance: should knowfreq 12%

answer

  1. a directive that suppressed nothing
  2. lives under linterOptions
  3. default warn since ESLint 9.0.0
  4. error makes stale directives fail the run
  5. a sibling setting for /* eslint */ comments

basics

~20 s

It reports eslint-disable and eslint-enable comments that suppressed nothing. In ESLint 10 it defaults to "warn", so stale directives appear as warnings; set to "error", each one counts as an error and fails the run with exit code 1.

solid answer

~40 s

`linterOptions.reportUnusedDisableDirectives` makes ESLint report disable directives that did not suppress any problem, and enable directives with no matching disable, with messages such as "Unused eslint-disable directive (no problems were reported from 'no-console')." Since ESLint 9.0.0 the default is `"warn"`, so stale directives show up as warnings without failing anything. Setting it to `"error"` turns each one into an error, so the run exits with 1 until the comment is removed. The CLI can override it: `--report-unused-disable-directives` reports them as errors, and `--report-unused-disable-directives-severity` takes `off`, `warn` or `error`; the two flags cannot be combined. A sibling setting, `reportUnusedInlineConfigs` (default `"off"`, added in 9.19.0), reports `/* eslint rule: ... */` comments that match what is already configured.

code

javascript · 11 lines
javascript
// eslint.config.js
import { defineConfig } from "eslint/config";

export default defineConfig([
  {
    linterOptions: {
      reportUnusedDisableDirectives: "error",
      reportUnusedInlineConfigs: "warn",
    },
  },
]);

go deeper

for a junior

Recall that ESLint can flag disable comments that no longer hide anything, and that by default they appear as warnings.

for a middle

Explain the setting's values and default, the two CLI flags and how they override the config, and the separate inline-config setting.

for a senior

Use "error" to force cleanup of stale directives in a legacy codebase, and anticipate the failures a rule fix in an upgrade will cause.

for a principal

Weigh strict stale-directive reporting against upgrade friction, and decide where in the pipeline each severity applies.

## What counts as an unused directive A **disable directive** (`eslint-disable`, `eslint-disable-line`, `eslint-disable-next-line`) exists to hide a reported problem. It becomes **unused** when no problem from the rules it names is reported in its region any more: the code changed, the rule was turned off, or a rule bug that caused a false positive was fixed. An `eslint-enable` comment is unused when there is no matching disable to re-enable. ESLint reports these with messages taken straight from its source: - "Unused eslint-disable directive (no problems were reported from 'no-console')." - "Unused eslint-disable directive (no problems were reported)." for a directive that names no rule - "Unused eslint-enable directive (no matching eslint-disable directives were found)." ## The setting and its default The setting lives under `linterOptions` in a configuration object: | Value | Effect | |---|---| | `"off"` (or `0`) | Unused directives are not reported | | `"warn"` (or `1`) | Reported as warnings; the exit code is unaffected. **The default since ESLint 9.0.0** | | `"error"` (or `2`) | Reported as errors; the run exits with code 1 | For legacy compatibility, `true` means `"warn"` and `false` means `"off"`. Before ESLint 9.0.0 these directives were not reported unless you asked; flat config's default changed that, which is why teams upgrading from ESLint 8 suddenly see a batch of new warnings. ## Overriding it from the command line 1. `--report-unused-disable-directives` takes no argument and reports unused directives **as errors**, whatever the config says. 2. `--report-unused-disable-directives-severity <off|warn|error>` sets the severity explicitly; without it, the config's `linterOptions` value applies. 3. Passing both flags is rejected: ESLint prints an error and exits with code 2. ## Why a team turns it up to "error" In the broadcaster's programme-guide app, several files carry disable comments nobody can explain. With the default `"warn"`, the stale ones are listed among hundreds of other warnings and nobody acts. Setting `reportUnusedDisableDirectives: "error"` makes every directive that no longer hides anything fail the run, so the team must delete it. That also closes a quieter risk: a leftover directive will silently hide a **future** violation of the same rule on that line. ESLint's own CLI documentation warns about the trade-off: - A rule can have a bug that reports a false positive, and someone adds a disable comment for it. - A patch release fixes the bug, and the comment now suppresses nothing. - With the setting at `"error"`, that upgrade alone produces a new error in code nobody touched. That is not a reason to avoid `"error"`, but it is a reason to expect a few failures after dependency upgrades and to read them as cleanup, not regressions. ## Cleaning up a legacy codebase in practice 1. Run once with `--report-unused-disable-directives-severity error` to list every stale directive without changing the config yet. 2. Delete the stale ones, and give each surviving directive a rule name and a `--` reason. 3. Set `linterOptions.reportUnusedDisableDirectives: "error"` in the config so the list cannot grow back. 4. Expect a handful of new reports after each ESLint or plugin upgrade, and treat them as deletions to make. Doing it in this order keeps the pull request that flips the setting small: by the time the config changes, the codebase already passes. ## The sibling setting: unused inline configs Inline rule comments such as `/* eslint eqeqeq: "error" */` change a rule's severity or options for one file. `linterOptions.reportUnusedInlineConfigs`, added in ESLint 9.19.0 and defaulting to `"off"`, reports such a comment when its severity and options match what the config already set, so it changes nothing. The matching CLI flag is `--report-unused-inline-configs <off|warn|error>`. | Setting | Reports | Default | |---|---|---| | `reportUnusedDisableDirectives` | Disable or enable directives that suppressed nothing | `"warn"` | | `reportUnusedInlineConfigs` | `/* eslint */` rule comments that change nothing | `"off"` | ## Mistakes to avoid - Assuming unused directives are invisible unless a flag is passed; in ESLint 10 they are warnings by default. - Assuming the bare CLI flag uses the config's severity; it reports errors. - Confusing an unused directive with an unused inline config; they are separate settings. - Turning on `noInlineConfig` to clean up stale directives; that ignores every directive instead of reporting the stale ones.

  • Why might a dependency upgrade alone make a run fail when this setting is "error"?
    If a rule previously reported a false positive and someone disabled it inline, a release that fixes the rule leaves that directive suppressing nothing. ESLint then reports it as unused, and at `"error"` that new report fails the run even though no application code changed. Delete the directive.
  • Does an unnamed `/* eslint-disable */` at the top of a file count as used?
    Only if some rule reported a problem somewhere in the region it covers. If the file is now clean for every rule, ESLint reports "Unused eslint-disable directive (no problems were reported)." Naming the rules makes the report specific, telling you which rule's exception has gone stale.

  • Says unused disable directives are never reported unless a CLI flag is passed
  • Believes the bare --report-unused-disable-directives flag reports warnings
  • Confuses reportUnusedDisableDirectives with reportUnusedInlineConfigs
  • Uses noInlineConfig to find stale disable comments
  • Thinks a leftover disable comment is harmless because the code is now clean

Assumes ESLint 10; reportUnusedDisableDirectives has defaulted to "warn" since ESLint 9.0.0, and reportUnusedInlineConfigs arrived in 9.19.0.