Sub topic 5
Tuning rules: severity and options
A preset gives you a starting rule set. This chapter covers how to change it: how loudly each rule reports, what each rule counts as a violation, and what happens when several config entries mention the same rule.
This chapter assumes you have a working eslint.config.mjs that applies tseslint.configs.recommended, as built in the earlier chapters. It also assumes you know what the flat config array is and how rule names are prefixed by their plugin.
The three severities
Every rule is in one of three states. You can write each state as a string or as a number. Strings are easier to read, so prefer them.
| String | Number | Effect |
|---|---|---|
| `'off'` | `0` | The rule does not run. |
| `'warn'` | `1` | The rule reports problems, but ESLint still exits with code 0. |
| `'error'` | `2` | The rule reports problems, and ESLint exits with code 1. |
The exit code is the practical difference between warn and error. A CI job fails only on a non-zero exit, so a warning never blocks a merge by default. Warnings also tend to pile up unnoticed, because nothing forces anyone to read them.
You can close that gap from the command line:
npx eslint . --max-warnings 0With --max-warnings 0, any warning makes ESLint exit with code 1. Many teams use warn locally and during a migration, and --max-warnings 0 in CI. That way the editor shows a softer signal, while the pipeline stays strict.
Setting a rule
Rules live in the rules key of a config object. The key is the full rule name, and the plugin's prefix is part of it. Rules from typescript-eslint start with @typescript-eslint/. Core ESLint rules have no prefix.
// eslint.config.mjs
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import { defineConfig } from 'eslint/config';
export default defineConfig(
eslint.configs.recommended,
tseslint.configs.recommended,
{
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-require-imports': 'off',
},
},
);The preset has already registered the plugin, so you do not import it again. Your object comes after the presets, so its settings win. The next section explains why order matters.
Passing options
Many rules accept options. To pass them, use an array. The first item is the severity, and the remaining items are the options.
// eslint.config.mjs
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import { defineConfig } from 'eslint/config';
export default defineConfig(
eslint.configs.recommended,
tseslint.configs.recommended,
{
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
},
],
'@typescript-eslint/consistent-type-imports': [
'warn',
{ prefer: 'type-imports', fixStyle: 'inline-type-imports' },
],
},
},
);Here no-unused-vars stays at error, but names that start with an underscore are exempt. That is a common convention for "I know this is unused". The consistent-type-imports rule is not part of the recommended preset, so this entry also turns it on, at warn.
This file shows what the options permit:
import { type Config, loadConfig } from './config';
export function handler(_event: unknown, config: Config): string {
try {
return loadConfig(config).name;
} catch (_error) {
return 'unknown';
}
}_event and _error are unused, but the patterns above exempt them. Rename _event to event and the rule reports it.
Where to find a rule's options
Each rule has a page on the typescript-eslint website. It lists the options, their types, and their defaults. Options are validated against a schema, so a misspelled option name or a wrong type makes ESLint stop with a configuration error. It does not silently ignore the mistake.
For rules from typescript-eslint, the options you give are merged with the rule's built-in defaults. You only write the fields you want to change. Core ESLint rules do not always behave this way, so check the rule's page before assuming it.
Options are not shared with the base rule
Some typescript-eslint rules are extended versions of a core ESLint rule. @typescript-eslint/no-unused-vars is one. The core no-unused-vars does not understand TypeScript syntax, so it reports false positives on type-only code. The recommended preset turns the core rule off and enables the TypeScript one. Settings for one rule do not carry over to the other, so configure only the @typescript-eslint/ version.
How later entries override earlier ones
The flat config is an array, and ESLint reads it in order. For each rule, the last entry that mentions it determines the result. Two cases matter, and they behave differently.
- A later entry sets only a severity, for example
'warn'. The severity is replaced, and any options from an earlier entry are kept. - A later entry gives an array, for example
['warn', { ... }]. The options from the earlier entry are replaced, not merged.
This config shows both cases:
// eslint.config.mjs
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import { defineConfig } from 'eslint/config';
export default defineConfig(
eslint.configs.recommended,
tseslint.configs.recommended,
{
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' },
],
},
},
{
// Case 1: severity only. argsIgnorePattern is still '^_'.
rules: {
'@typescript-eslint/no-unused-vars': 'warn',
},
},
);Now the rule is a warning, and the ^_ pattern still applies. If the last entry were ['warn', { varsIgnorePattern: '^_' }], the argsIgnorePattern would be gone. The second entry replaces the whole option object. The mistake shows up as new reports on arguments that used to be exempt.
The diagram below summarizes how ESLint resolves one rule across the config array.
Choosing a severity
Severity is a team decision about what a report means. These guidelines work well in practice:
- Use
errorfor rules that catch likely bugs, such asno-floating-promisesorno-unused-vars. A report means the code should not merge. - Use
warnfor rules you are rolling out. This lets a team see the volume of problems before it blocks work. Set a date to promote the rule toerroror remove it. - Use
offfor rules whose cost exceeds their value in your codebase. Turn a rule off in the config rather than hiding every report with inline comments.
Common mistakes
- Wrong rule name. A rule key such as
'no-explicit-any'without the@typescript-eslint/prefix refers to a core rule that does not exist. ESLint stops with an error that names the missing rule. - Options without a severity. Writing
[{ prefer: 'type-imports' }]is invalid. The first array item must be the severity. - Placing overrides before the preset. If your
rulesobject comes beforetseslint.configs.recommended, the preset overrides your choices. Put your own entries last. - Replacing options by accident. As shown above, an array entry throws away earlier options. When you only want to change the severity, write the string.
Checking the resolved setting
To see what ESLint actually applies to a file after all entries are merged, print the resolved config:
npx eslint --print-config src/index.tsFind the rule in the output. It shows the final severity as a number, followed by the final options. If a setting does not behave as you expect, this output tells you which entry won.
Exercise
Your config has an entry that sets '@typescript-eslint/no-unused-vars' to ['error', { argsIgnorePattern: '^' }]. A later entry sets it to ['warn', { varsIgnorePattern: '^' }]. A third, even later entry sets it to 'error'. What are the final severity and options, and would an argument named _unused be reported?
Show answer
The final severity is error. The second entry replaced the options object, so the options are { varsIgnorePattern: '^' }. The third entry is severity only, so it keeps those options. The argsIgnorePattern from the first entry is gone, so unused as an argument is reported. To keep both patterns, put both in the options of the entry that sets them.