ESLint で ignore 指定したファイルが無視されない
ESLint v9 (flat config) では .eslintignore は廃止され、eslint.config.js 内の ignores プロパティでのみ無視指定する。
グローバル ignore にしたい場合は files を併記せず ignores 単独のオブジェクトで宣言し、否定パターン(!)は後段に置く。
公開:
要約
ESLint で「無視したはずのファイルがチェックされる」原因の大半は、v9 の flat config 移行に伴うもの。
v9 では .eslintignore を読まなくなり、eslint.config.js の ignores キーが唯一の指定方法。
グローバル無視にしたい場合は files を併記せず { ignores: [...] } 単独のオブジェクトで書く。
glob は ** の有無や否定パターンの順序に注意する。
よくある原因
- リポジトリを ESLint v9 にアップグレードしたが、
.eslintignoreを残したまま運用している。
v9 はこのファイルを参照しない。 eslint.config.jsの途中に{ files: ["src/**/*.ts"], ignores: ["src/legacy/**"] }のように書いてしまい、src/legacy/**のチェックを「特定ルール構成から外す」だけになっていて、ESLint 全体のスキャン対象からは外れていない。- ディレクトリを
distとだけ書いても、それは「distという名前のファイル」にしかマッチしない。
配下まで除外したいならdist/**。 eslint src/a.tsのようにファイルを直接渡すと、ignore 設定があっても警告付きで実行される。
CI ログでは「無視されていないように見える」原因になる。
解決策
1. flat config でグローバル ignore を書く
// eslint.config.js
export default [
{ ignores: ["dist/**", "coverage/**", "**/*.generated.ts"] },
// ... 他の設定オブジェクト
];ignores 単独のオブジェクトはグローバルに作用する(公式ドキュメント(新しいタブで開く))。files を併記すると、その files で絞り込んだ範囲内の局所 ignore になってしまう。
2. パターンの粒度を直す
ignores: [
"node_modules/**",
"dist/**",
"**/__generated__/**",
"!src/important.generated.ts" // 例外で含めたいファイルは ! を後ろに
]否定パターン(!)は 後段 に置く。
順序を逆にすると効かない。
3. legacy 設定を維持する場合
package.json で eslint@^8 のままなら .eslintignore は有効。
ただしルートからの相対パスで書く必要があり、サブパッケージ単位の ignore は各ディレクトリに .eslintignore を置く。
4. CLI に渡すファイルを絞る
npm run lint のスクリプトを eslint . にしておけば ignore が確実に効く。eslint <ファイル名> を直書きしている場合は、ignore よりも CLI 引数が優先される点に注意。
実行例
実際に上記の手順を node:20 環境で動かすと、.eslintignore に dist を記載した状態で eslint . を実行した際に ESLintIgnoreWarning が出力されて同ファイルは無視されず、dist/generated.js の no-unused-vars エラーが検出されて終了コード 1 となる一方、eslint.config.js の ignores 単独オブジェクトへ切り替えると終了コード 0 で dist が正しく除外されることが確認できる。
== versions ==
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
v20.20.2
Python 3.11.2
git version 2.39.5
This is not the tsc command you are looking for
To get access to the TypeScript compiler, tsc, from the command line either:
- Use npm install typescript to first add TypeScript to your project before using npx
- Use yarn to avoid accidentally running code from un-installed packages
v10.6.0
== run ==
--- ESLint v9 を install ---
v9.39.4
--- v9 で廃止された .eslintignore に dist を書く(v9 は読まない想定)---
--- npx eslint . (.eslintignore は効かず dist が lint される想定)---
(node:116) ESLintIgnoreWarning: The ".eslintignore" file is no longer supported. Switch to using the "ignores" property in "eslint.config.js": https://eslint.org/docs/latest/use/configure/migration-guide#ignoring-files
(Use `node --trace-warnings ...` to show where the warning was created)
/tmp/tmp.bgp8jOCzuX/dist/generated.js
1:7 error 'unused' is assigned a value but never used no-unused-vars
✖ 1 problem (1 error, 0 warnings)
eslint の終了コード: 1
--- 解決: .eslintignore を廃し flat config に ignores 単独オブジェクトを置く ---
eslint の終了コード: 0(0 = dist が無視された)— 2026-07-06 時点の出力