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:
- Clone this minimal reproducible case: https://github.com/EvgenyOrekhov/eslint-config-hardcore/tree/no-files-matching-the-pattern-bug
npm installnpm 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
- [Tests] add test case for #1645 — committed to ljharb/eslint-plugin-import by ljharb 4 years ago
- [Tests] add test case for #1645 — committed to ljharb/eslint-plugin-import by ljharb 4 years ago
- [Tests] add test case for #1645 — committed to ljharb/eslint-plugin-import by ljharb 4 years ago
@EvgenyOrekhov
I was having a relevant issue with the cli
eslint --ext .js,.jsx,.ts,.tsx srcand alternativeeslint src/**/*.{js,jsx,ts,tsx}what worked for me to “fix” this error was to add quotes… ** facepalm **
eslint --ext ".js,.jsx,.ts" srcandeslint \"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-bugbranch after you clone the repo. I getNo files matching the pattern "C:\eslint-config-hardcore" were found.error.I updated the code to use
eslint .command. The goal is to makeeslint .command (without any extra options like--ext) work even when there are no*.jsfiles 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
--extoption, havingoverrideswith specific extensions will be enough. Maybe it will fix this issue withno-unused-modules.@ljharb Tried doing that, plus the same extensions in the ‘files’ array - got the error.