eslint-plugin-import: [import/no-unused-modules] - "No files matching the pattern" error

I’m using both eslint-plugin-import and eslint-plugin-json. When there are only *.json files in my project, I get “No files matching the pattern” error from the import/no-unused-modules rule, and ESLint crashes.

Steps to reproduce:

  1. Clone this minimal reproducible case: https://github.com/EvgenyOrekhov/eslint-config-hardcore/tree/no-files-matching-the-pattern-bug
  2. npm install
  3. npm test

Actual result:

> no-files-matching-the-pattern-bug@0.0.0 test C:\eslint-config-hardcore
> eslint --ext .js,.json .


Oops! Something went wrong! :(

ESLint: 6.8.0.

No files matching the pattern "C:\eslint-config-hardcore" were found.
Please check for typing mistakes in the pattern.

npm ERR! Test failed.  See above for more details.

Expected result: there should be no “No files matching the pattern” error, there should be only one warning from eslint-plugin-json

> no-files-matching-the-pattern-bug@0.0.0 test C:\eslint-config-hardcore
> eslint --ext .js,.json .


C:\eslint-config-hardcore\invalid.json
  1:2  error  Expected a JSON object, array or literal  json/*

✖ 1 problem (1 error, 0 warnings)

npm ERR! Test failed.  See above for more details.

When I remove the import/no-unused-modules rule from .eslintrc.json, the problem goes away.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 1
  • Comments: 39 (18 by maintainers)

Commits related to this issue

Most upvoted comments

@EvgenyOrekhov

I was having a relevant issue with the cli

eslint --ext .js,.jsx,.ts,.tsx src and alternative eslint src/**/*.{js,jsx,ts,tsx}

what worked for me to “fix” this error was to add quotes… ** facepalm **

eslint --ext ".js,.jsx,.ts" src and eslint \"src/**/*.{js,jsx,ts,tsx}\"

NOT a fix, but it looks like the CLI accepts this

@ljharb I updated all dependencies (including all transitive ones) in my repro case. Still getting the same error. Looking forward to the next release of eslint-plugin-import!

@ljharb Great, looks like it will! Feel free to close this issue. I will check it once the next version is released.

@ljharb Make sure you checkout the no-files-matching-the-pattern-bug branch after you clone the repo. I get No files matching the pattern "C:\eslint-config-hardcore" were found. error.

I updated the code to use eslint . command. The goal is to make eslint . command (without any extra options like --ext) work even when there are no *.js files in the folder.

I know that in ESLint 7 they will have some changes to the way ESLint handles file extensions. For example, they will not require using the --ext option, having overrides with specific extensions will be enough. Maybe it will fix this issue with no-unused-modules.

@ljharb Tried doing that, plus the same extensions in the ‘files’ array - got the error.