--max-warnings global limit without per-rule exclusion
0 reputation · 20 Aug 2022, 08:03 UTC
0 reputation · 20 Aug 2022, 08:03 UTC
ESLint CLI provides --max-warnings N to make the run exit non-zero when total warnings across all linted files exceed N. The threshold aggregates warnings from every rule configured at warn severity.
The design goal is to allow CI to fail on a warning budget for a specific set of rules while still reporting informational warnings from other rules without counting them toward the limit. Errors are tracked independently and always cause a non-zero exit.
The current behavior aggregates all warn-level messages together with no documented per-rule cap or rule-exclusion boundary. Plugin-authored rules participate in the same warning aggregation as core rules, and the behavior is described for both eslintrc and flat config setups.
Can --max-warnings be scoped to a subset of rules or rule groups? Is there a supported configuration to exclude specific rules from the warning total while keeping them reported? Does the aggregation behavior differ between eslintrc and flat config setups?
33775 reputation · 20 Aug 2022, 08:40 UTC
No. --max-warnings N cannot be scoped to a subset of rules or rule groups. ESLint sums every message whose final severity is warn across all linted files and compares that single total against N. There is no supported CLI option or configuration key—in either eslintrc or flat config—that excludes specific rules from the count while still reporting them.
Confirmed: the threshold applies to the aggregate warning count of the run; errors are tracked separately and always produce a non-zero exit regardless of the warning budget. Rules set to off emit no messages and contribute nothing. Plugin-authored rules participate in the same aggregation as core rules because the count is computed from the final result set, not from rule provenance.
The consistency across config formats follows from that design: since the total is derived from completed lint results, the configuration engine does not change how warnings are tallied. This reflects ESLint 8.x-era behavior; re-verify flag interactions after any major version upgrade.
Because the boundary cannot be drawn inside ESLint, move it outside:
warn, applying --max-warnings; run a second pass with all rules at warn and no limit for informational reporting. This roughly doubles lint time and requires maintaining two configurations or override sets.-f json, filter messages by ruleId in a small script, and enforce your own threshold. Preserve native exit-code handling so genuine errors still fail the pipeline—a custom script that swallows the exit code can mask real failures in CI.Confirm the aggregation in your own setup:
warn, run npx eslint . --max-warnings 0 and check that the exit code is non-zero.off and rerun; the exit code should become zero.error and rerun with a high --max-warnings value; the exit should remain non-zero..eslintrc file and an eslint.config.js flat config to confirm the count matches.One detail that changes the recommendation: whether your CI can execute a Node.js post-processing step for the JSON output, or whether you need a pure-CLI pipeline, which pushes you toward the two-pass approach.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.