skip to content

With ESLint 10 in a monorepo, why does `eslint .` at the root now apply `packages/map-tiles/eslint.config.js` to that package, and how do you control it?

level: seniorimportance: should knowfreq 8%

answer

  1. where the search starts
  2. each linted file's own directory
  3. the nearest config file, no merging
  4. ESLint 9 started at the cwd
  5. --config stops the search

basics

~20 s

ESLint 10 looks for eslint.config.* from each linted file's directory upward, so files under packages/map-tiles use the nearest config, and only that one. ESLint 9 started at the working directory. --config names one file and stops the search.

solid answer

~40 s

Since 10.0.0, ESLint locates `eslint.config.*` by starting in the directory of **each linted file** and walking up to the filesystem root; ESLint 9 started from the current working directory unless the `v10_config_lookup_from_file` flag was set. In ESLint 10 that flag is removed and passing it is an error. A package's own config therefore now lints its files even when you run from the root. The nearest file is the whole configuration: nothing is merged from parent directories, so the root's rules and global ignores do not reach that package, and patterns in the package config are relative to the package. To control it, delete stray package configs, make each one import a shared base array, or pass `--config eslint.config.js` to use one file for everything.

code

javascript · 14 lines
javascript
// packages/map-tiles/eslint.config.js
import { defineConfig, globalIgnores } from "eslint/config";
import globals from "globals";
import base from "../../eslint.base.js";

export default defineConfig([
  globalIgnores(["dist/"]),
  base,
  {
    name: "birdmap/map-tiles",
    files: ["**/*.js"],
    languageOptions: { globals: globals.node },
  },
]);

go deeper

for a junior

Recall that ESLint 10 picks the eslint.config file nearest to each linted file, not the one where you ran the command.

for a middle

Explain that the nearest config is the whole configuration, with no merging from parent folders, and that --config stops the search.

for a senior

Diagnose an upgrade where a forgotten package config suddenly applies, choose between one root config, shared-base package configs and a --config pin, and check that ignores survive.

for a principal

Weigh one root config against per-package configs for a large repository: ownership, how a shared base is versioned, and how many places an engineer must read.

## What changed in ESLint 10 ESLint 10.0.0 made a new **configuration file lookup** the default. For every file it lints, ESLint now starts in **that file's directory** and searches upward toward the filesystem root until it finds an `eslint.config.*` file. ESLint 9 started the search from the **current working directory** and used the file it found there for everything; the per-file behaviour was available in 9 only behind the `v10_config_lookup_from_file` feature flag. ESLint 10 removed the flag, and passing it now produces an error. In a repository like this: ``` eslint.config.js (root: web app rules, global ignores) apps/web/src/map.js packages/map-tiles/eslint.config.js (written long ago, never used) packages/map-tiles/build.js ``` `eslint .` at the root used to lint `packages/map-tiles/build.js` with the root config. In ESLint 10 it uses `packages/map-tiles/eslint.config.js`, because that file is the nearest one. A config nobody ran for years is suddenly live. ## The nearest file is the whole config Flat config files do not cascade. The first `eslint.config.*` found is the complete configuration for that file, as if eslintrc's `root: true` were always set. Consequences: - The root config's **rules** do not apply inside `packages/map-tiles`. - The root config's **global ignores** do not apply either; the package config needs its own for `dist/`. - Patterns in the package config are **relative to `packages/map-tiles`**, so `files: ["**/*.js"]` there means that package's JavaScript files. - An array imported from elsewhere and spread into the package config is evaluated relative to the **package** config's directory too; a root pattern like `"apps/web/**"` matches nothing there. ## Three ways to take control | Approach | How | Fits when | |---|---|---| | One root config | Delete package configs; scope settings with `files` or `basePath: "packages/map-tiles"` | One team owns all packages and wants one place to read | | Per-package configs on a shared base | Each package exports `defineConfig([...base, own objects])`, importing `base` from a shared file | Packages differ (browser vs Node.js) or are owned by different teams | | Pin the old behaviour | Run with `--config eslint.config.js` | A short transition while package configs are cleaned up | `--config` (or `-c`) names one file and **disables the search**: every file uses that config, and its `files` and `ignores` patterns are then evaluated relative to the **current working directory**, not to the config file. `--no-config-lookup` goes further and uses no config file at all, leaving only rules passed with `--rule`. The ESLint 10 migration guide recommends `--config` for anyone who relied on the working-directory lookup. ## Choosing between the approaches - **Ownership decides first.** If one team reviews every package's lint changes, one root config is simplest to read and audit. - **Runtimes decide second.** Packages for different runtimes (browser code beside Node.js scripts) can still live in one root config, scoped with `files` or `basePath`; separate configs are not required for that. - **Independence decides last.** Packages released or owned separately benefit from their own config, built on a shared base so common rules change in one place. - **Count the readers.** Every additional config file is another place an engineer must check when a rule surprises them. ## `basePath` in a single root config `basePath` scopes an object to a subdirectory, and the object's `files` and `ignores` patterns become relative to it: ```js { name: "birdmap/map-tiles", basePath: "packages/map-tiles", files: ["**/*.js"], languageOptions: { globals: globals.node }, } ``` Combined with `extends`, one `basePath` can scope a whole preset to a package. It keeps a single file readable without long path prefixes on every pattern. ## Diagnosing the switch 1. Run `eslint --debug packages/map-tiles/build.js` and look for the config file it loaded. 2. Run `eslint --print-config packages/map-tiles/build.js` to see what that file now receives. 3. Search the repository for every `eslint.config.*` and decide, file by file, whether it should exist. 4. Check that each surviving package config has the global ignores the root used to provide. ## Pitfalls - Running ESLint from inside a package and from the root should now give the same result for that package's files, because both runs find the same nearest config; a remaining difference usually comes from a `--config` in one of the scripts. - A stale `v10_config_lookup_from_file` in a CI script or `ESLINT_FLAGS` fails the run after the upgrade; remove it. - Expecting parent and package configs to merge produces rules that silently vanish in the package.

  • After the upgrade, generated files in `packages/map-tiles/dist` start failing lint, although the root config ignores `**/dist/`. Why?
    Those files now use `packages/map-tiles/eslint.config.js`, the nearest config, and configs are never merged, so the root's global ignores do not apply. Add `globalIgnores(["dist/"])` to the package config, or remove the package config and keep one root config.
  • With `--config eslint.config.js`, what are the `files` patterns relative to?
    The current working directory. Naming a file with `--config` both stops the search and changes the anchor, so running the same command from a subdirectory changes which files the patterns match. Run it from the repository root, where the patterns were written.
  • What happens if a script still passes `--flag v10_config_lookup_from_file` after the upgrade to ESLint 10?
    ESLint reports an error, because the flag was removed when its behaviour became the default. Delete it from the command line, from `ESLINT_FLAGS`, or from the `flags` passed to the Node.js API.

  • Expects the root config and a package config to merge for package files
  • Says ESLint 10 always uses the config in the working directory
  • Believes --config keeps patterns relative to the config file's folder
  • Assumes the root's global ignores still cover a package with its own config
  • Thinks the v10_config_lookup_from_file flag is still needed in ESLint 10

Assumes ESLint 10: since 10.0.0 the config file is searched from each linted file's directory, and the v10_config_lookup_from_file flag that previewed it in ESLint 9 is removed.