In ESLint 10's flat config, when two stacked presets set the same rule differently, which setting wins, and where must your own override go?
answer
- position, not preset prestige
- later matching object wins
- extends goes before the object's own keys
- overrides last, presets first
- a later files-scoped object can switch one off
basics
~20 sThe preset that comes later in the flattened config array wins for files both match. Put your overrides after every preset: in a later object, or in the rules of the object whose extends lists the presets.
solid answer
~40 sFlat config has no preset hierarchy. `defineConfig()` flattens everything into one array, and for each file ESLint merges the objects that match it in order, so a later object's setting for a rule replaces an earlier one. Inside `extends`, presets are inserted in list order before the object that lists them, so that object's own `rules` override all of them. If `@crewdeck/eslint-config` sets `no-unused-vars` to `warn` and a generated config then appends `js.configs.recommended`, recommended's `"error"` wins, because it comes later. So order presets from general to specific, put your overrides last, and to relax a preset rule for some files add a later object with those `files` and `"off"`. A config that only turns rules off is no different: it must come after the presets it switches off.
code
javascript · 21 lines// apps/roster/eslint.config.js
import js from "@eslint/js";
import crewdeck from "@crewdeck/eslint-config";
import { defineConfig } from "eslint/config";
export default defineConfig([
{
files: ["src/**/*.{js,jsx}"],
// general preset first, the team's preset after it
extends: [js.configs.recommended, crewdeck],
rules: {
// own rules come after both presets, so they win
"no-console": "warn",
},
},
{
// later object: relaxes one preset rule for fixtures only
files: ["src/**/*.fixtures.js"],
rules: { "crew/no-raw-dates": "off" },
},
]);go deeper
Recall the one rule: when several matching config objects set the same rule, the later one wins, so overrides go after the presets.
Walk through how extends expands to the presets in list order followed by the object itself, and show a later files-scoped object switching one rule off.
Diagnose a surprising severity by printing the merged config for one file and reading which object came last, instead of editing the shared package.
Set a house order for every app, general presets, then the team package, then local overrides, so clashes resolve the same way across repositories.
## No hierarchy, only order ESLint's flat config has no idea that one preset is more important than another. Whatever you stack, `@eslint/js`'s recommended rules, a plugin preset, a team's **shareable config** or your own object, ends up as one flat **config array**. When ESLint lints a file it takes every object in that array that matches the file, in order, and merges them. For each rule, a **later object's setting replaces an earlier one**. Precedence is therefore purely positional: whichever object sits later in the array wins. ## How `extends` orders things `defineConfig()` expands `extends` before ESLint sees the config. For an object `{ files, extends: [A, B], rules }` it produces, in this order: 1. `A`, limited to the object's `files`; 2. `B`, limited to the same `files`; 3. the object itself, with its own `rules` and other keys. So within one object, a later preset in the list beats an earlier one, and the object's own settings beat both. A preset that is itself an array, such as a shareable config, contributes all its objects at that position, in its own order. ## A worked clash `@crewdeck/eslint-config` stacks `js/recommended` and then sets `no-unused-vars` to `["warn", { argsIgnorePattern: "^_" }]`, so unused `_`-prefixed arguments pass. One app's config, started from ESLint's getting-started example, lists `crewdeck` and then `js.configs.recommended`. The results: | Array order | Final severity of `no-unused-vars` | |---|---| | `js.configs.recommended`, then `crewdeck` | `"warn"`, crewdeck's setting is later | | `crewdeck`, then `js.configs.recommended` | `"error"`, recommended's setting is later | | either order, then the app's own `rules` | whatever the app sets | In the second row the developer sees errors for a rule the team's package sets to warn, and blames the package. The fix is ordering, not editing the package. When a later object sets only a severity, the options from the earlier setting are kept, which is how `argsIgnorePattern` survives in that row. ## Turning a preset rule off for some files To relax one preset rule for a subset of files, add an object **after** the presets with those `files`: - `{ files: ["src/**/*.fixtures.js"], rules: { "crew/no-raw-dates": "off" } }` turns the rule off only for fixtures. - The same object placed before the preset loses, because the preset is later. - A global `ignores` object is the wrong tool: it stops ESLint from linting those files at all. - A rule from a plugin keeps its registered prefix, so the override must say `crew/...` exactly as the preset does. A config whose only job is to switch rules off, such as one that disables rules another tool owns, follows the same rule: it is just another array entry and must come after everything it switches off. ## An ordering checklist When several presets are stacked in one app, a fixed order makes clashes predictable: 1. Global ignores; they apply to every object wherever they sit, but first is easiest to read. 2. Core presets, such as `js/recommended`. 3. Plugin presets, such as the React hooks and jsx-a11y presets. 4. The team's shareable config, which encodes the team's decisions about the presets above it. 5. Configs that only switch rules off. 6. The app's own overrides, then any files-scoped exceptions such as fixtures or tests. Each layer can then rely on overriding the ones before it, and a reader can tell from position alone which setting wins. ## Seeing the result When the outcome surprises you, print the merged config for one file with `--print-config <file>`, or open the config inspector with `--inspect-config`, which lists the named objects that matched. Naming the objects in a shared config (`name: "crewdeck/base"`) makes that output readable. ## Pitfalls - Spreading a preset into your own object, `{ ...preset, rules: { ... } }`, replaces the preset's whole `rules` object at the JavaScript level; spread `...preset.rules` too, or use `extends`. - Putting your overrides in the first object of the array, before the presets, makes them dead settings. - Expecting a plugin preset to beat core settings, or the reverse, misreads the model: only position matters.
- Why does `{ ...crewdeckBase, rules: { eqeqeq: "off" } }` lose all of crewdeck's other rules?Object spread is plain JavaScript: your `rules` key replaces the preset's whole `rules` object before ESLint ever merges anything. Spread the preset's rules as well, `rules: { ...crewdeckBase.rules, eqeqeq: "off" }`, or keep the preset whole in `extends` and set your rule in the object's own `rules`.
- How do you find out which preset supplied a rule's final setting for one file?Run `eslint --print-config src/roster.jsx` to see the merged config for that file, or `eslint --inspect-config` to open the config inspector, which shows each named object that matched. Objects produced by `extends` carry names like `crewdeck/base > js/recommended`, so the source is readable.
Stacking presets is like laying transparent sheets on an overhead projector: where two sheets mark the same spot you see the top one, so your corrections must be the last sheet laid down.
- A plugin's preset always outranks ESLint's core recommended settings.
- Your own config object wins no matter where it sits in the array.
- The first preset to configure a rule decides its setting.
- Two presets configuring the same rule cause a configuration error.
- To relax a preset rule for tests, put the off setting before the preset.
Assumes ESLint 10 with defineConfig() and extends (exported from eslint/config since 9.22.0); the later-object-wins merge has been flat config's rule since it became the default in ESLint 9.