In ESLint, what do the rule severities "off", "warn" and "error" do, and which one makes a lint run fail?
answer
- three values, three numbers
- 0, 1 and 2 as aliases
- reported is not the same as failing
- exit code 1 needs an error
- array form: severity first, options after
basics
~20 s"off" (0) disables a rule, "warn" (1) reports its violations without touching ESLint's exit code, and "error" (2) reports them and makes the run exit with code 1, so only error-level rules fail a build by default.
solid answer
~50 sEvery rule in an ESLint config gets one of three severities: `"off"` or `0` turns it off, `"warn"` or `1` reports violations as warnings, and `"error"` or `2` reports them as errors. The difference that matters in a pipeline is the exit code: warnings do not affect it, while a single reported error-level violation makes ESLint exit with code 1, which is what fails a CI job or a pre-commit check. That is why a config that sets most rules to `"warn"` can print thousands of problems for a year and never fail. Severity is set in the `rules` object, either as a bare value or as the first element of an array whose remaining elements are the rule's options, and it can also be set per file with an inline `/* eslint rule: ... */` comment.
go deeper
Recall the three values and their numbers, and that only "error" changes the exit code. Be able to read a rules object and say which entries can fail a build.
Explain the array form, with the severity always first and options after, and that inline comments can change a severity for one file and are applied last.
Diagnose a pipeline that has been green for months while printing thousands of warnings, and explain why promoting specific rules to error is the lever inside the config.
Frame severities as policy: which rules a team agrees will block merges, which stay advisory, and who may switch a rule off for a set of files.
## The three severities ESLint does not have a separate on/off switch and a separate strictness level for a rule. A single value, the **severity**, does both. Each rule ID in the `rules` object of a configuration object maps to one of three values, written either as a string or as its numeric alias: | Severity | Numeric alias | Is the rule run? | How violations appear | Effect on the exit code | |---|---|---|---|---| | `"off"` | `0` | No | Not reported | None | | `"warn"` | `1` | Yes | Reported as warnings | None | | `"error"` | `2` | Yes | Reported as errors | Exit code 1 when triggered | ESLint's own documentation puts it in exactly these words: a warning "doesn't affect exit code", while for an error the "exit code is 1 when triggered". ## Where a severity is written - **In `eslint.config.js`**, inside a configuration object's `rules` key: `eqeqeq: "error"`. - **With options**, as an array whose first element is always the severity: `"no-unused-vars": ["error", { args: "none" }]`. The severity is never written anywhere else in the array. - **Inline, in one file**, with a block comment such as `/* eslint eqeqeq: "off", curly: "error" */`. Inline configuration is applied after the config file and wins for that file. - **As numbers**, in either place: `/* eslint eqeqeq: 0, curly: 2 */` means the same as the string form. A rule that a plugin defines is written with the plugin's namespace as a prefix (`"example/rule1": "warn"`), but the severity values are the same three. ## What the run does with them When ESLint finishes linting, it counts errors and warnings separately: 1. If no error-level violation was reported, the run exits with **0**, however many warnings were printed. 2. If at least one error-level violation was reported, the run exits with **1**. 3. Exit code **2** is not a severity at all; it means a configuration problem or an internal error, such as an invalid severity value or invalid rule options. A warning threshold can turn warnings into a failure too, but that is a CLI flag on the CI run, not a property of the rule, and it is off by default. ## Why an all-warn config gates nothing Picture a public broadcaster's TV programme-guide web app: a six-year-old JavaScript codebase whose config sets most rules to `"warn"`. Its CI job has printed about 1,900 warnings on every run for a year and has never once failed. Nothing is broken in ESLint here; the config is doing exactly what it says. Because `"warn"` never changes the exit code, the job is green, the pull request merges, and the warning count drifts upward. The moment the team decides that `no-unused-vars` and `eqeqeq` must actually stop merges, the only lever inside the rule's own setting is to set them to `"error"`. ESLint's documentation describes the intended split: - **`"error"`** is the normal setting for a rule you want enforced in CI, pre-commit checks and pull request merges, because it produces a non-zero exit code. - **`"warn"`** suits a rule being introduced that will become an error later, a rule that flags something other than a likely bug, or a rule that may produce false positives and needs a human to judge. - **`"off"`** is for a rule you do not want at all, including one switched on by a shared preset you otherwise keep. ## Severities inside presets Shared configurations choose severities too. `js.configs.recommended` from `@eslint/js` sets every rule it enables, `no-unused-vars` included, to `"error"`, while `eqeqeq` is not part of it at all and has to be added by hand. A project that spreads a preset and then writes its own `rules` object after it can: - switch a preset rule off with `"off"` in the later object; - relax one to `"warn"` while keeping whatever options the preset chose; - add rules the preset leaves out, at the severity the team wants. This is how the broadcaster's app ended up all-warn in the first place: someone copied a preset's rule list into the config years ago and downgraded every entry to `"warn"` to get a green build on day one. Nothing ever promoted them back. ## Traps candidates fall into - Assuming any reported problem fails the run. Only errors do. - Assuming a warning limit is on by default. It is not; without a flag on the command line, warnings never fail. - Writing the options first and the severity second in the array. The severity must be the first element. - Thinking `"off"` merely hides output. An off rule is not run at all. - Treating `0`, `1` and `2` as different from the strings. They are exact aliases, in config files and in inline comments.
- Can the same rule be "error" in most of the codebase and "off" in one file?Yes. A later configuration object whose `files` pattern matches that file can set the rule to `"off"`, or the file itself can carry `/* eslint rule-name: "off" */`. Inline comments are applied after all config-file settings, so the comment wins for that file. Prefer the config object when the exception is a whole group of files, because it is visible in one place.
- Why might a team deliberately leave a rule at "warn" for good?ESLint's docs suggest `"warn"` for rules that cannot be certain they found a problem and so need manual review, and for rules that flag something other than a buildtime or runtime error. Reporting those keeps them visible in the editor and in the log without blocking a merge on a judgement call.
- Says a rule set to warn fails the CI job by itself
- Believes warnings beyond some default limit make ESLint exit with code 1
- Puts rule options before the severity in the array
- Thinks "off" still runs the rule and just hides its output
- Treats 1 and "warn" as different settings