eslint: Add an option to not throw an error on an unmatched pattern
The version of ESLint you are using.
ESLint: 5.1.0.
The problem you want to solve.
Since breaking behaviour change 8b7c6eaed39e8506dba1aa6e57b1d0e2fdc351c3 #7390 #10143 bundled in ESLint 5, a fatal error is thrown if any file pattern return no files.
My company is using a generic ESLint configuration/runner for all our projects, and we are pretty happy with that:
eslint \
--ext .js --ext .jsx --ext .mjs \
-- src test "packages/*/src" "package/*/test"
The problem is that not ALL of our projects matches the same patterns, and we got this error since we upgraded to eslint@5
No files matching the pattern "test" were found.
Please check for typing mistakes in the pattern.
We don’t want to implement custom code to check for pattern existence before appending them to eslint CLI parameters (and we where really happy with eslint@4 behaviour on this particular case).
NOTE: This issue is a bit related to https://github.com/eslint/eslint/issues/9977
Your take on the correct solution to problem.
Add a CLI option (exactly like how proposed here) not to throw errors on unmatched patterns.
Something like --no-error-on-missing-files
or --no-error-on-unmatched-pattern
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 60
- Comments: 40 (15 by maintainers)
Commits related to this issue
- fix: upgrade eslint to v5 N.b. needs to manually run patterns to lint through the glob module before linting until eslint/eslint#10587 is resolved. Which might not be. — committed to ipfs/aegir by achingbrain 6 years ago
- fix: upgrade eslint to v5 N.b. needs to manually run patterns to lint through the glob module before linting until eslint/eslint#10587 is resolved. — committed to ipfs/aegir by achingbrain 6 years ago
- fix: upgrade eslint to v5 (#298) * fix: upgrade eslint to v5 N.b. needs to manually run patterns to lint through the glob module before linting until eslint/eslint#10587 is resolved. * chore: ... — committed to ipfs/aegir by achingbrain 6 years ago
- New: Add no-error-on-unmatched-pattern flag (fixes #10587) Add flag to prevent errors when a pattern or --ext is not matched — committed to ncraley/eslint by ncraley 5 years ago
- New: Add no-error-on-unmatched-pattern flag (fixes #10587) Add flag to prevent errors when a pattern or --ext is not matched — committed to ncraley/eslint by ncraley 5 years ago
- New: Add no-error-on-unmatched-pattern flag (fixes #10587) Add flag to prevent errors when a pattern or --ext is not matched — committed to ncraley/eslint by ncraley 5 years ago
- New: Add no-error-on-unmatched-pattern flag (fixes #10587) (#12377) Add flag to prevent errors when a pattern or --ext is not matched — committed to eslint/eslint by ncraley 5 years ago
I think there are relatively few use cases for this option (one of which might be running eslint in an integration), but I don’t object to adding it. That said, if you’re encountering an error like this when running ESLint from the command line, the solution should usually be to stop trying to lint non-existing files, not to add a flag to make ESLint ignore your errors. This issue has a lot of 👍s in comparison with the narrowness of the use case, which makes me suspect that some people are misunderstanding what the error message is saying.
I think this issue was closed prematurely. Many people (including me) want to be able to save time and share ESLint scripts across different projects (with sometimes non-existing paths in the glob).
It could be easily solved by adding a new CLI flag to skip glob entries that result in no paths.
If somebody from admin team are still reading this, please consider reopening this issue.
Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.
Thanks for contributing to ESLint and we appreciate your understanding.
Per discussion in the 2019/04/11 TSC meeting, this is now accepted. (Apologies for not following up here.)
This definitely should be re-opened and fixed. Just faced with this strange behaviour on version v5.15.0. tested with Node 6 & 8.
Eslint should NOT fail if it can’t find some files from a pattern.
I’ll reopen this. We need to at least evaluate this as a TSC for sure.
I’m gonna take a look at this over the weekend and see if it’s something I can tackle
Hi @brunoscopelliti, have you tried quoting the globs like
eslint "app/**" --ext .js
? It’s possible that your shell is expanding the globs to a list of files before passing the files to ESLint, and the expanded list of files includes some folders that don’t contain any lintable files.I’d like to second that. We’re working on legacy code which is close to impossible to refactor to our eslint rules, so we use
git log
to generate a list of changed files that eslint should run on. But sometimes this will included deleted files, breaking our workflow. Adding an option to just keep going would be extremely helpful.@not-an-aardvark correct. And I did it before v5.
Tooling should exit silently if it doesn’t apply to any files.
This proposal has been accepted. PRs welcome!
I don’t know what my schedule will be this afternoon, so in case I don’t make it to the TSC meeting, I left a 👍 on the TSC summary above. It seems like the new default behavior works for most users, but the use cases described here justify an opt-out.
If you’ll allow me to bike-shed a bit, I have a slight preference for option names like unmatched glob or unmatched pattern, since “missing files” sounds ambiguous to me. Having a long option name shouldn’t be an issue since the use case here is a write-once shared script, and users wouldn’t be typing it on every invocation.
TSC Summary:
In ESLint 5.0.0, we started throwing errors when nonexistent directories or files, or glob patterns that don’t match any files, were passed to ESLint. The assumption was that users would want to know when a file wasn’t being linted as it could be due to a misspelling. However, this has caused unforeseen side-effects for some tooling, where the intention is to create lint scripts that will lint certain files as they are created in a new project.
Numerous members of the community are asking that we add a CLI option to enable the old behavior on an opt-in basis. Example option names:
--no-error-on-missing-files
,--no-error-on-unmatched-pattern
TSC Question:
Should we invite contributions for a new CLI option to suppress errors when lint target files/directories are not found, or globs match no patterns?
This seems reasonable to me as long as the default behavior remains unchanged. Let’s see what others say.
Edit: typo
Anyone has some workaround for this issue. I’m migrating from js to typescript and eslint not support
as
operator then I disable to lintts
files but doing this brake the linting of the rest ofjs
files. 😦@ozaytsev86 In your case, you might be able to use
--diff-filter=d
to remove the deleted paths from consideration and avoid the problem.I just tried to upgrade to eslint@5 and i ran into the same issue.
I have a “starter-kit” project with all the backbone code that I then fork to create other projects.
I have an eslint command that is trigged by the ci to lint my sources files, as well as my test files. The starter-kit project doesn’t have any test files since it has nothing to test, but i don’t think the linting script should fail because of it…
Here are the scripts
And the Error
No files matching the pattern "." were found.
Thanks for fixing this, or at least provide an option to not fail on empty test suites. Otherwise I have to add a dummy empty test file in the starter-kit project, which is lame.
I would like this too as some of my projects dont have certain files. I make lots of projects a day so its hard to constantly adjust the command.