-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[import/no-unused-modules] - "No files matching the pattern" error #1645
Comments
Note that it's not about |
This is an error coming from eslint itself. By default, if you're linting "no javascript files", it's probably a bug. If you have no |
Indeed; it's the only rule where we're using eslint's FileEnumerator logic (which is what the command-line eslint uses as well). You can fix it by configuring here |
If you have no .js files, then there's nothing to analyze - json files don't import anything. If you have |
@ljharb I would like to be able to use my config in any project, irregardless of which types of files they have, without having to readjust the |
I'm not sure how; many rules - including that one - require per-project config, and |
I just tried running |
I see what you're saying; but the assumption is that an eslint config is always running on the full set of files that config applies to. One thing you could do is configure using |
@ljharb Tried this:
export default 123;
{
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": ["import"],
"overrides": [
{
"files": ["*.ts"],
"rules": {
"import/no-unused-modules": [
"error",
{
"missingExports": false,
"unusedExports": true
}
]
}
}
]
}
|
|
@ljharb Yeah, adding So, in order to have a generic config that would work with several file extensions without throwing any errors, I would have to do this: {
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": ["import"],
"overrides": [
{
"files": ["*.js"],
"rules": {
"import/no-unused-modules": [
"error",
{
"src": ["**/*.js"],
"missingExports": false,
"unusedExports": true
}
]
}
},
{
"files": ["*.ts"],
"rules": {
"import/no-unused-modules": [
"error",
{
"src": ["**/*.ts"],
"missingExports": false,
"unusedExports": true
}
]
}
},
{
"files": ["*.jsx"],
"rules": {
"import/no-unused-modules": [
"error",
{
"src": ["**/*.jsx"],
"missingExports": false,
"unusedExports": true
}
]
}
},
{
"files": ["*.tsx"],
"rules": {
"import/no-unused-modules": [
"error",
{
"src": ["**/*.tsx"],
"missingExports": false,
"unusedExports": true
}
]
}
}
]
} I guess I could live with that, but I would rather prefer to not have to do it. |
Yes, that seems right to me. One last try for a single config - what if you do |
@ljharb Tried doing that, plus the same extensions in the 'files' array - got the error. |
In that case I think the multiple configs is the only current option. It seems useful to preserve the error if any of the globs you provide result in matching zero files. |
If I had to do it for every rule, that would be horrible. |
Very true, but most rules apply to a file; this one has to check a whole codebase. |
@ljharb Trying to fix it here: https://github.com/EvgenyOrekhov/eslint-config-hardcore/pull/59/files. Something weird is going on, now I'm getting a false positive: https://travis-ci.org/EvgenyOrekhov/eslint-config-hardcore/builds/659511799#L213. Am I missing something? |
Hmm, i wonder if with this approach, TS files not used by TS files (etc) would be considered unused. In other words, I’m no longer sure if it’s possible for this rule to support the use case of running on “not every extension the codebase uses at once”. In other words, this might after all require each project to configure it themselves (ie, it might not be possible to configure it in a generic sense, for a shared config) |
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 |
@ljharb I upgraded ESLint to 7.0.0 and removed the |
@EvgenyOrekhov when i clone your minimal repro, and run |
@ljharb Make sure you checkout the I updated the code to use |
@ljharb I added a Travis CI config, you can see the log here: https://travis-ci.com/github/EvgenyOrekhov/eslint-config-hardcore/builds/169082082. |
aha, the branch :-) thanks, will look. |
@EvgenyOrekhov sooooo yay? I reproduced your error, and then i /path/to/eslint-config-hardcore/invalid.json
1:2 error Expected a JSON object, array or literal json/*
✖ 1 problem (1 error, 0 warnings) Looks like the next release will fix this? |
@ljharb Great, looks like it will! Feel free to close this issue. I will check it once the next version is released. |
Thanks for the repro case :-) if there's a trivial way to add it as a test case to this repo, so we don't regress, that would be awesome too. |
Hmm; I just tried again and the error occurs again, even with it linked - but when I try to make a test case in this repo, it provides the expected error. I wonder if merely updating your lockfile with |
I've added the test case to master; hopefully that's accurate and also prevents future regressions. |
@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 I updated eslint-plugin-import in my repro case to 2.21.1, and I'm still getting the same error: :( |
I’ll reopen - the next step, i think, is for you to try to make a PR with a failing test case, since my existing test cases pass :-/ |
I was having a relevant issue with the cli
what worked for me to "fix" this error was to add quotes... ** facepalm **
NOT a fix, but it looks like the CLI accepts this |
@mcabs3 I need to make it work without specifying extensions: |
it works on eslint but, on version and it works and it is my {
"root": true,
"extends": "next/core-web-vitals",
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"rules": {
"no-console": "warn",
"semi": "off",
"no-extra-semi": "error",
"semi-spacing": "error",
"semi-style": "error"
}
}
]
} |
@marcos-venicius if the comma form for extensions doesn’t work, that’s an eslint bug; please file it with them. |
If you guys using |
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 theimport/no-unused-modules
rule, and ESLint crashes.Steps to reproduce:
npm install
npm test
Actual result:
Expected result: there should be no "No files matching the pattern" error, there should be only one warning from eslint-plugin-json
When I remove the
import/no-unused-modules
rule from.eslintrc.json
, the problem goes away.The text was updated successfully, but these errors were encountered: