Sub topic 4
Choosing Rules and Severity Levels
This chapter assumes you have ESLint installed and an eslint.config.js file that loads js.configs.recommended. It also assumes you can run npx eslint . from the command line. Here you will learn how to turn individual rules on and off, how to pass options to them, and how each severity level affects your build.
The three severity levels
Every ESLint rule has a severity. You can write it as a string or as a number:
| Severity | Number | Effect | Exit code if triggered |
|---|---|---|---|
| `"off"` | `0` | The rule does not run | 0 |
| `"warn"` | `1` | The problem is reported, and the run still passes | 0 |
| `"error"` | `2` | The problem is reported, and the run fails | 1 |
The exit code is the part that matters in automation. Scripts, pre-commit hooks and CI only look at the exit code, so warnings alone never block anything.
Severity plus options
Some rules accept options. To pass them, write the rule as an array: the severity comes first, followed by the options.
// eslint.config.js
import js from "@eslint/js";
export default [
js.configs.recommended,
{
files: ["**/*.js"],
rules: {
// Severity only
"no-unused-vars": "warn",
// Severity plus a string option
eqeqeq: ["error", "always"],
// Severity plus an object option
"no-console": ["warn", { allow: ["warn", "error"] }],
// Turn off a rule that the recommended set enables
"no-empty": "off",
},
},
];Later config objects override earlier ones. That is why your own rules block goes after js.configs.recommended.
Choosing between warn and error
Here is a practical guideline:
- Use
"error"for likely bugs, such aseqeqeq,no-undefandno-unreachable. - Use
"warn"for problems you want to see but that should not block work, such asno-consoleduring development or a rule you are introducing gradually. - Use
"off"for rules that do not fit your project, and for formatting rules that Prettier will handle.
Warnings tend to pile up because nothing forces anyone to fix them. To make them count in CI, cap them:
npx eslint . --max-warnings 0Common mistakes
- Misspelled rule names. ESLint stops with a "Could not find rule" error. Look up the exact name in the rules reference.
- Invalid severity values. Values like
"warning"ortruecause a configuration error. Onlyoff/warn/erroror0/1/2are accepted. - Wrong option shape. Each rule validates its options against a schema, so
eqeqeq: "always"fails. Options must go inside an array after the severity. - Config order. If a shared config comes after your
rulesblock, it can silently override your settings.
Exercise
Your config contains js.configs.recommended followed by { rules: { "no-unused-vars": "warn" } }. A file has one unused variable and nothing else wrong. What exit code does npx eslint . return, and what changes if you add --max-warnings 0?
Show answer
It returns exit code 0, because the only problem is a warning. With --max-warnings 0, the single warning exceeds the limit, so ESLint exits with 1 and the build fails.
Exercise
An earlier config sets "no-console": ["error", { allow: ["error"] }]. Your later block sets "no-console": "warn". Is console.error still allowed?
Show answer
Yes. Your block changes only the severity, so ESLint keeps the earlier allow: ["error"] option. The rule now warns on other console calls instead of failing the run.