In ESLint 10's flat config, what happens to a rule's options when a later config object or inline comment sets only its severity?
answer
- later object takes precedence
- severity alone is special
- options kept, only severity swapped
- a new options array replaces, never merges
- inline comments aligned in ESLint 9.0.0
basics
~20 sThe earlier options survive: a later "warn" or ["warn"] replaces only the severity, so ["error", "never"] becomes ["warn", "never"]. A later array that carries options replaces the earlier options entirely, and since ESLint 9.0.0 inline comments follow the same rule.
solid answer
~40 sWhen several configuration objects set the same rule, ESLint merges them with the later object taking precedence, but a later setting that holds only a severity is treated specially: it keeps the options from before and swaps the severity. So `semi: ["error", "never"]` followed by `semi: "warn"` ends as `["warn", "never"]`; a one-element array such as `["warn"]` behaves the same way. A later setting that includes options replaces the earlier options wholesale: option objects are not deep-merged, and anything you leave out falls back to the rule's own default. Since ESLint 9.0.0 an inline `/* eslint curly: "warn" */` comment works the same way; before 9.0.0 it reset the rule to its default options. To force the defaults inline now, the comment must name at least one option.
code
javascript · 22 lines// eslint.config.js
import js from "@eslint/js";
import { defineConfig } from "eslint/config";
export default defineConfig([
js.configs.recommended,
{
rules: {
"no-unused-vars": ["warn", { args: "none", ignoreRestSiblings: true }],
eqeqeq: ["warn", "always", { null: "ignore" }],
},
},
{
files: ["src/**/*.js"],
rules: {
// severity only: becomes ["error", { args: "none", ignoreRestSiblings: true }]
"no-unused-vars": "error",
// options given: replaces ["always", { null: "ignore" }] entirely
eqeqeq: ["error", "smart"],
},
},
]);go deeper
Remember that the later setting wins and that a bare severity keeps any options set earlier.
Explain the special case for severity-only settings, why option objects replace instead of merging, and how inline comments changed in ESLint 9.0.0.
Use print-config to prove the final options when a rule behaves differently than the config seems to say, and spot an override that silently dropped options.
Decide how shared presets and local overrides divide responsibility, so consumers change severities without forking a preset's options.
## Severity and options travel together A rule setting in ESLint is either a bare **severity** (`"error"`, `2`) or an **array** whose first element is the severity and whose remaining elements are the rule's **options**: `["error", "never"]`, `["warn", { args: "none" }]`. In flat config, several **configuration objects** in the exported array can match the same file, and each may set the same rule. Deciding which objects match a file is a separate subject; this answer starts once two of them do. ## The merge rule for one rule ID ESLint combines the two settings with the later object taking precedence, with one special case: | Earlier setting | Later setting | Result | Why | |---|---|---|---| | `["error", "never"]` | `"warn"` | `["warn", "never"]` | Severity only, so earlier options are kept | | `["error", "never"]` | `["warn"]` | `["warn", "never"]` | A one-element array also counts as severity only | | `["error", "never"]` | `["warn", "always"]` | `["warn", "always"]` | Later options replace earlier ones | | `["warn", { args: "none" }]` | `["error", { caughtErrors: "none" }]` | `["error", { caughtErrors: "none" }]` | Option objects are not deep-merged | The last row is the one that surprises people. The second object did not add `caughtErrors` to the first object's options; it replaced the whole options list. `args` is now whatever the rule defaults to, which for `no-unused-vars` is `"after-used"`. ## A worked case In the broadcaster's programme-guide app, a base object configures two rules with options, and a later object promotes them to errors for the application source: - `no-unused-vars` is promoted with a bare `"error"`, so it keeps `args: "none"` and `ignoreRestSiblings: true`. - `eqeqeq` is promoted with `["error", "smart"]`, so its earlier `{ null: "ignore" }` is gone; `"smart"` has its own exceptions instead. Reading the final value is easiest with `--print-config` on a real file, which prints the computed configuration without linting. ## Inline comments since ESLint 9.0.0 Inline configuration comments are applied after every config-file setting, and they now merge the same way: 1. Config file: `curly: ["error", "multi"]`. 2. File comment: `/* eslint curly: "warn" */`. 3. Result in that file: `["warn", "multi"]`. Before ESLint 9.0.0, the same comment replaced the config entirely and the rule ran with its **default options**. ESLint's migration guide calls this out because a file that relied on the old reset now behaves differently. The documented way to force the defaults inline today is to name at least one option, for example `/* eslint curly: ["warn", "all"] */`. Two other inline details are worth knowing: - Since ESLint 9.0.0, two `/* eslint */` comments for the same rule in one file are no longer silently resolved: the first is applied and the others are reported as lint errors. - The comment can carry a description after two or more hyphens, which is ignored when the setting is parsed. ## Overriding a preset's choices The same merge applies when the earlier setting comes from a shared preset rather than your own object: - `js.configs.recommended` sets `no-unused-vars` to a bare `"error"`, so a later `["error", { args: "none" }]` simply adds options; there were none to replace. - If a preset sets a rule with options and you only want it quieter, a later `"warn"` keeps the preset's options, which is usually what you want. - If you want different options, your array becomes the complete option list; read the rule's documentation for the defaults of anything you leave out. Because inline comments are applied last, a single file can still diverge from both the preset and your overrides, which is one more reason to keep severity-only comments rare and explained. ## Why this design helps - **Shared presets stay usable.** A preset can choose careful options, and a consumer can change only how loudly the rule reports without copying those options. - **Severity changes stay small in review.** Promoting a rule from `"warn"` to `"error"` is a one-word diff, not a re-declaration that might drift from the original options. - **Option changes are explicit.** Because options replace rather than merge, the last array you write is the complete option set, which is easy to read but easy to get wrong if you expect a merge. ## Common mistakes - Expecting two option objects for the same rule to merge key by key. - Assuming the first object to configure a rule wins; precedence goes to the later object. - Copying ESLint 8 knowledge that a severity-only inline comment resets options. - Re-declaring a preset's full options just to change the severity, then letting them drift.
- How do you make a later config object reset a rule to its default options?A bare severity cannot do it, because severity-only settings keep the earlier options. Write an array that carries at least one option, such as the rule's default value spelled out: `eqeqeq: ["error", "always"]`. That array replaces the earlier options list, and anything it leaves out falls back to the rule's own defaults.
- After upgrading from ESLint 8, a file with `/* eslint curly: "warn" */` starts reporting different curly violations. Why?Since ESLint 9.0.0 a severity-only comment keeps the options from the config file instead of resetting the rule to its defaults. If the config sets `curly: ["error", "multi"]`, the file now runs `["warn", "multi"]`. To get the defaults back, write an option explicitly, such as `/* eslint curly: ["warn", "all"] */`.
- Expects two option objects for the same rule to be merged key by key
- Says the first config object to set a rule wins
- Believes a severity-only inline comment resets the rule to its default options in ESLint 10
- Thinks ["warn"] drops the earlier options while "warn" keeps them
- Re-declares a preset's full options just to change a rule's severity
Assumes ESLint 10 flat config; inline comments with only a severity keep config-file options since ESLint 9.0.0, while earlier releases reset them to the rule's defaults.