Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to not throw an error on an unmatched pattern #10587

Closed
yvele opened this issue Jul 10, 2018 · 40 comments · Fixed by #12377, basics/vector#127, thinkwee/thinkwee.github.io#39, alxtford/numconv#46 or WoTTsecurity/api#773
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion cli Relates to ESLint's command-line interface enhancement This change enhances an existing feature of ESLint help wanted The team would welcome a contribution from the community for this issue

Comments

@yvele
Copy link

yvele commented Jul 10, 2018

The version of ESLint you are using.

ESLint: 5.1.0.

The problem you want to solve.

Since breaking behaviour change 8b7c6ea #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 #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

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Jul 10, 2018
@kaicataldo kaicataldo added core Relates to ESLint's core APIs and features evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion cli Relates to ESLint's command-line interface enhancement This change enhances an existing feature of ESLint and removed triage An ESLint team member will look at this issue soon core Relates to ESLint's core APIs and features labels Jul 10, 2018
@kaicataldo
Copy link
Member

kaicataldo commented Jul 10, 2018

This seems reasonable to me as long as the default behavior remains unchanged. Let's see what others say.

Edit: typo

@platinumazure
Copy link
Member

Agreed, it would be better to opt-in to this so that by default we are helping users avoid typos in their patterns.

@wei
Copy link

wei commented Jul 12, 2018

Ignore my comment. Thanks @not-an-aardvark , I was doing eslint ./*/ --ext .js --ignore-path .gitignore which worked in 4.19 but was breaking with a similar looking error. Changing it to eslint . --ext .js --ignore-path .gitignore fixed it.

@not-an-aardvark
Copy link
Member

not-an-aardvark commented Jul 12, 2018

I don't think an error is thrown for nonexistent paths in .gitignore or .eslintignore. Are you sure that's creating an error?

@not-an-aardvark not-an-aardvark changed the title Don't throw error on unmatched pattern Add an option to not throw an error on an unmatched pattern Jul 12, 2018
@not-an-aardvark
Copy link
Member

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.

@isnifer
Copy link

isnifer commented Aug 15, 2018

Any update on this? I would like to describe my case:
I have a monorepo:

packages
  /api
  /app
  /shared
  /web

My web project runs in docker. And I don't add app code inside it. But my only script to lint all projects contains a path to app too. So, in v5 this command is broken inside docker.
I would like to see a parameter to not throw an error about unmatched paths.

@not-an-aardvark
Copy link
Member

@isnifer Thanks for explaining your use case. I'm a bit confused -- if you don't have any app code, couldn't you simply remove the path to app/ from your script that lints all projects?

@isnifer
Copy link

isnifer commented Aug 15, 2018

@not-an-aardvark no, I have a code. But app and web are independent projects that use both shared and api. I don't use different configs and linter commands. I have the only config, the only lint command, and many projects.

.eslintrc
.eslintignore
packages/
package.json
lerna.json
...etc

Actually, I have found a solution for this:

# my v4 command to lint js
"lint": "eslint -c .eslintrc.js 'packages/api/**/*.js' 'packages/app/src/**/*.js' 'packages/app/__tests__/**/*.js' 'packages/app/scripts/**/*.js' 'packages/shared/**/*.js' 'packages/web/src/**/*.js' 'packages/web/__tests__/**/*.js' --cache"

# my v5 command to lint js
"lint": "eslint -c .eslintrc.js 'packages/**/*.js' --cache",

It works little bit longer when cold start, but then there is no problem.

@not-an-aardvark
Copy link
Member

@isnifer I'm still not sure I understand -- what is the error message when you use your "v4 command" with ESLint v5? Is there a particular pattern that ESLint says isn't matching any files?

@isnifer
Copy link

isnifer commented Aug 15, 2018

@not-an-aardvark

> eslint -c .eslintrc.js 'packages/api/**/*.js' 'packages/app/src/**/*.js' 'packages/app/__tests__/**/*.js' 'packages/app/scripts/**/*.js' 'packages/shared/**/*.js' 'packages/web/src/**/*.js' 'packages/web/__tests__/**/*.js' --cache


Oops! Something went wrong! :(

ESLint: 5.2.0.
No files matching the pattern "packages/app/__tests__/**/*.js" were found.
Please check for typing mistakes in the pattern.

Because I don't need my RN app code inside docker for web

@not-an-aardvark
Copy link
Member

So to make sure I understand, you want to use the same lint script in multiple environments, but in certain environments some of the files are absent?

@isnifer
Copy link

isnifer commented Aug 16, 2018

@not-an-aardvark correct. And I did it before v5.

@brunoscopelliti
Copy link

I've just upgraded to latest eslint@5.*, and this check is causing troubles to me as well.

I usually use eslint as: eslint app/** --ext .js.
Then in the .eslintignore file I exclude the undesired directory (eg. app/dist)...

In this case I get the following error:

No files matching the pattern "app/dist" were found.
Please check for typing mistakes in the pattern.

IMHO eslint shouldn't trigger the error for folders which are explicitly ignored. What do you think about this?

@brunoscopelliti
Copy link

Sorry for the double post.

I've also tried to run eslint as eslint app/folder1/** app/folder2/** app/file1 --ext .js.

That's not optimal cause if I add a folder, or file I've to update the build script as well, but I need a workaround for now.

However the above causes troubles as well, because I've some folders (eg. in app/folder2) which don't contain javascript file, but only json (eg. app/folder2/data/foo.json).

So I would really need a way to opt-out from this stricter check.

@not-an-aardvark
Copy link
Member

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.

@brunoscopelliti
Copy link

Hi @not-an-aardvark, I didn't know that was possible; quoting the globs worked for me. Thank you for the help.

@lucasrossini
Copy link

lucasrossini commented Sep 11, 2018

I've created a bash script as a workaround for this issue:

#!/bin/bash

GLOB_PATTERN=${1:-"."}

OUTPUT="$(script --quiet --return --command "eslint ${GLOB_PATTERN}" /dev/null)"
EXIT_CODE=${?}

if [[ "${EXIT_CODE}" == "2" ]]; then
  exit 0
fi

echo "${OUTPUT}"
exit "${EXIT_CODE}"

Just call it passing the desired pattern as an argument.
Hope it helps!

achingbrain added a commit to ipfs/aegir that referenced this issue Nov 21, 2018
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.
achingbrain added a commit to ipfs/aegir that referenced this issue Nov 21, 2018
N.b. needs to manually run patterns to lint through the glob module
before linting until eslint/eslint#10587 is resolved.
hugomrdias pushed a commit to ipfs/aegir that referenced this issue Nov 21, 2018
* 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: swap glob for globby
@kaicataldo
Copy link
Member

This proposal has been accepted. PRs welcome!

@kaicataldo kaicataldo added help wanted The team would welcome a contribution from the community for this issue Hacktoberfest Recommended issue for those participating in Hacktoberfest https://hacktoberfest.digitalocean.com/ labels Sep 29, 2019
@ncraley
Copy link
Contributor

ncraley commented Oct 4, 2019

I'm gonna take a look at this over the weekend and see if it's something I can tackle

ncraley added a commit to ncraley/eslint that referenced this issue Oct 4, 2019
Add flag to prevent errors when a pattern or --ext is not matched
ncraley added a commit to ncraley/eslint that referenced this issue Oct 4, 2019
Add flag to prevent errors when a pattern or --ext is not matched
ncraley added a commit to ncraley/eslint that referenced this issue Oct 4, 2019
Add flag to prevent errors when a pattern or --ext is not matched
@kaicataldo kaicataldo removed the Hacktoberfest Recommended issue for those participating in Hacktoberfest https://hacktoberfest.digitalocean.com/ label Nov 19, 2019
btmills pushed a commit that referenced this issue Dec 20, 2019
Add flag to prevent errors when a pattern or --ext is not matched
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 19, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.