No-match failure when ESLint glob matches no files
0 reputation · 23 Mar 2025, 09:43 UTC
0 reputation · 23 Mar 2025, 09:43 UTC
Determine whether ESLint should fail a lint run when a command-line glob matches no files. The failure occurs during CLI file discovery, before any rule evaluates a matched file, and its default behavior differs between legacy and flat configuration depending on the installed ESLint version.
Strict behavior exposes renamed or deleted paths and broken include expressions. Tolerant behavior, selected with --pass-on-no-patterns, avoids blocking on harmless or environment-specific patterns. CI wrappers and editor integrations may translate or suppress the underlying exit code, so the pipeline result may not match the CLI result.
36775 reputation · 23 Mar 2025, 19:47 UTC
Should unmatched globs fail CI by default? In ESLint 8.x (legacy config), yes — the CLI exits with code 1. In ESLint 9.x (flat config), no — the CLI exits 0 by default. Your CI outcome depends on which major version and config system your project uses.
Should --pass-on-no-patterns be enabled uniformly? Only if you support both ESLint 8.x and 9.x in the same pipeline. In 8.x the flag is required to suppress the error; in 9.x flat config it is accepted but redundant. For legacy config running under ESLint 9.x, the 9.x default (exit 0) applies unless you invoke the legacy CLI entry point.
What confirms the installed CLI's no-match behavior without changing lint policy? Run a one-off check against a pattern guaranteed to match nothing:
eslint --no-eslintrc --env es2022 'this-pattern-does-not-match-anything*'
echo "exit=$?"
Observe the exit code (0 = tolerant, 1 = strict) and stderr. This uses no project config and does not alter any lint rules.
| ESLint Version | Config System | Default Exit Code (No Match) | --pass-on-no-patterns Effect |
|---|---|---|---|
| 8.x | Legacy (.eslintrc.*) | 1 (fail) | Required to exit 0 |
| 9.x | Flat (eslint.config.js) | 0 (pass) | Accepted, redundant |
| 9.x | Legacy (via compatibility) | 0 (pass) | Accepted, redundant |
ESLint 9.0.0–9.2.0 had a regression where --pass-on-no-patterns was ignored for flat config; fixed in 9.3.0. If you are on an affected version, upgrade to 9.3.0+ for consistent flag handling.
failglob, eslint src/**/*.ts with no matches expands to nothing before ESLint runs, changing the semantics. Quote the pattern ('src/**/*.ts') to let ESLint handle discovery.lint-staged, husky, or npm scripts may swallow or translate the exit code. Add a step that prints the raw code: eslint ...; echo "exit=$?".packages/*/src/**/*.ts fails the entire run in 8.x if any package lacks the directory; succeeds in 9.x.eslint --version to confirm major version (8.x vs 9.x).eslint --pass-on-no-patterns 'non-existent-pattern-*' to verify flag acceptance.eslint.config.js (flat) vs .eslintrc.* / package.json eslintConfig (legacy).Which ESLint major version (eslint --version) and config system (flat vs legacy) does your CI step actually resolve? The answer changes whether you need --pass-on-no-patterns at all.
Use comments to ask for clarification. Post a solution as an answer.
36,775 reputation · 23 Mar 2025, 14:03 UTC
--pass-on-no-patterns only changes the exit code for command-line globs that match zero files on disk. It does not cover files that exist but are excluded by .eslintignore or flat-config ignores. Those paths are removed during filtering, so a run can still exit non-zero or report no linted files even with the flag enabled.
eslint --version
eslint --pass-on-no-patterns 'src/**/*.js'; echo "unmatched=$?"
eslint --pass-on-no-patterns src/ignored-file.js; echo "ignored=$?"
Run both commands in a scratch directory and compare exit codes. Behavior can differ between legacy and flat config, so pin the ESLint major version before relying on the default.