ESLint で ignore 指定したファイルが無視されない
ESLint で ignore 指定したファイルが無視されないときは、eslint.config.js に { ignores: [...] } を単独で書けば直る。
v9 は .eslintignore を読まない。
公開: 更新:
npx eslint . … (node:94) 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.6tNPmlsIzc/dist/generated.js
npx eslint .
2026-11-14 に node:20(ESLint 9.39.5 / Node.js 20.20.2) で実際に打って取った出力。検証環境の詳細
要約
ESLint で「無視したはずのファイルがチェックされる」原因の大半は、v9 の flat config 移行に伴うものである。
v9 では .eslintignore を読まなくなり、eslint.config.js の ignores キーが唯一の指定方法になった。
グローバル無視にしたい場合は、files を併記せず { ignores: [...] } 単独のオブジェクトで書く。
glob では、先頭の **/ の有無と否定パターンの順序で結果が変わる。
実行例
node:20 の ESLint 9.39.5 では、.eslintignore に dist を書いても ESLintIgnoreWarning が出て無視されず、終了コード 1 になった。ignores 単独オブジェクトに切り替えると、dist が除外されて終了コード 0 になった。
v9.39.5$ npx eslint .
(node:94) 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.6tNPmlsIzc/dist/generated.js
1:7 error 'unused' is assigned a value but never used no-unused-vars
✖ 1 problem (1 error, 0 warnings)
$ echo $?
1$ npx eslint .
$ echo $?
0— 2026-11-14 時点の出力
検証環境Node.js 20.20.2 / npm 10.8.2 / Python 3.11.2 / 2026-11-14 検証(ほか 2 件)
- 検証日
- 実行環境
node:20Debian GNU/Linux 12 (bookworm)- バージョン
- Node.js 20.20.2
- npm 10.8.2
- Python 3.11.2
- Git 2.39.5
- ESLint 9.39.5
この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。
解決策
1. flat config でグローバル ignore を書く
// eslint.config.js
export default [
{ ignores: ["dist/**", "coverage/**", "**/*.generated.ts"] },
// ... 他の設定オブジェクト
];ignores 単独のオブジェクトはグローバルに作用する(公式ドキュメント(新しいタブで開く))。files を併記すると、その files で絞り込んだ範囲内の局所 ignore になってしまう。
2. パターンの粒度を直す
ignores: [
"**/node_modules/",
"**/dist/", // どの階層の dist も除外する
"**/__generated__/**",
"!src/important.generated.ts" // 例外で含めたいファイルは ! を後ろに
]否定パターン(!)は 後段 に置く。
順序を逆にすると効かない。
なお dist/** のようにディレクトリの中身を丸ごと除外した場合、ESLint はそのディレクトリを走査しなくなるため、配下のファイルを ! で戻すことはできない。
3. legacy 設定を維持する場合
package.json で eslint@^8 のままなら、.eslintignore は有効である。
ただしルートからの相対パスで書く必要があり、サブパッケージ単位の ignore は各ディレクトリに .eslintignore を置く。
4. CLI に渡すファイルを絞る
$ npx eslint dist/bundle.js
0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to disable file ignore settings or use "--no-warn-ignored" to suppress this warning
✖ 1 problem (0 errors, 1 warning)直接渡しても除外対象なら lint はされない。
警告が邪魔なら --no-warn-ignored、逆に除外を無効化して検査したいなら --no-ignore を付ける。npm run lint のスクリプトを eslint . にしておけば、そもそもこの警告は出ない。
よくある原因
- リポジトリを ESLint v9 にアップグレードしたが、
.eslintignoreを残したまま運用している。
v9 はこのファイルを参照しない。 eslint.config.jsの途中に{ files: ["src/**/*.ts"], ignores: ["src/legacy/**"] }のように書いてしまった。
これではsrc/legacy/**のチェックを「特定ルール構成から外す」だけで、ESLint 全体のスキャン対象からは外れていない。ignoresのパターンは設定ファイルのある階層を起点に解釈される。distと書けばその直下のdist/は中身ごと除外されるが、packages/app/distのように深い階層にある同名ディレクトリは残る。
どこにあっても除外したいなら**/dist/と書く。eslint src/a.tsのように除外対象のファイルを直接渡すとFile ignored because of a matching ignore pattern.という 警告だけが出る。
ファイル自体は lint されておらず終了コードも 0 だが、CI ログにファイル名が並ぶので「無視されていないように見える」原因になる。