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 · May be fixed by nl253/BlogUI#3, O330oei/node#4, O330oei/node#11 or armonkahil/TriviaGame#2
Closed

Comments

@yvele
Copy link

@yvele 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 eslint bot added the triage label Jul 10, 2018
@kaicataldo
Copy link
Member

@kaicataldo 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

@platinumazure platinumazure commented Jul 10, 2018

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 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 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

@not-an-aardvark not-an-aardvark commented Jul 12, 2018

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 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

@not-an-aardvark not-an-aardvark commented Aug 15, 2018

@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 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

@not-an-aardvark not-an-aardvark commented Aug 15, 2018

@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 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

@not-an-aardvark not-an-aardvark commented Aug 15, 2018

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 isnifer commented Aug 16, 2018

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

@brunoscopelliti
Copy link

@brunoscopelliti brunoscopelliti commented Aug 21, 2018

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

@brunoscopelliti brunoscopelliti commented Aug 21, 2018

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

@not-an-aardvark not-an-aardvark commented Aug 21, 2018

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

@brunoscopelliti brunoscopelliti commented Aug 22, 2018

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 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 added 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
@ncraley
Copy link
Contributor

@ncraley 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
btmills added a commit that referenced this issue Dec 20, 2019
Add flag to prevent errors when a pattern or --ext is not matched
@eslint eslint bot locked and limited conversation to collaborators Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.