-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Bug: [flat config] Global ignores
matches differently from non-global ignores
#17213
Comments
Hi @mxxk, thanks for the issue. > minimatch('ignored/file.js', 'ignored/')
false
> minimatch('ignored/file.js', 'ignored/**')
true You would need to specify Edit: I now see your point about the @mdjermanovic please verify. Thanks. |
It is intentional. Patterns in global In my opinion, this is indeed confusing. I think we should update the non-global |
I agree it's confusing, although I'm not sure of the complexity of the fix. If it's an easy fix then let's fix it. |
@Rec0iL99 @mdjermanovic please be sure to take a stab at priority and impact when triaging. :) |
I'm also in favor of changing the behavior of non-global |
@fasttime I would be happy to take a stab at it. Since I'm not familiar with the code, would you mind including some pointers to the following places in the flat config part of the codebase?
|
Thanks for your interest @mxxk! I haven't looked into most of this code before, but I'll try to point out what I think are the relevant parts. I will also do my best to answer any questions that may pop up while you progress.
This is where a directory matched by a global ignore pattern is filtered out: eslint/lib/eslint/eslint-helpers.js Line 279 in 4f5440d
The implementation of The
This is also done in the https://github.com/humanwhocodes/config-array/blob/v0.11.9/src/config-array.js#L302 The function When you feel confident enough to start working on a change, this is what I would do next:
|
I believe this commit should fix it, if anyone wants to take a quick look: |
Thanks for the fix @nzakas, that was fast! If we are going to treat a non-universal ignore pattern like ignores: ["src/", "!src/js/"] // same as ["src/**", "!src/js/**"] The rest looks fine to me. Maybe @mdjermanovic can verify? |
I don't think I'd expect that |
Negated patterns should have no effect in this case because the parent directory |
Also, the original example should work without the slash too. {
// Ignores directory tree ignored/
ignores: ["ignored"]
} {
files: ["**/*.js"],
// Should ignore directory tree ignored/
ignores: ["ignored"]
} |
I see the point: that's how |
Eh okay, I'm waving the complexity flag here. I don't like the path this is going down. If we need to make So my suggestion is that we just update the documentation to reflect the current reality. When |
I've drafted PR #17239 to update the documentation as suggested in the above comment. |
In the 2023-06-01 TSC Meeting, we've agreed to not make any code changes and instead update the documentation to explicitly mention that non-global ignores can only match files and so patterns like |
Environment
Node version: v18.12.1
npm version: 8.19.2
Local ESLint version: v8.41.0
Global ESLint version: none
Operating System: Linux or MacOS
What parser are you using?
Default (Espree)
What did you do?
Configuration
eslint-global-ignore.config.js
eslint-files-ignore.config.js
file.js
andignored/file.js
What did you expect to happen?
Not sure what is the correct intended behavior here, so raising this issue for the maintainers' consideration. Based on the documentation (Globally ignoring files with
ignores
), it looks likeignores
can match and ignore an entire directory tree:However, if the same
ignores
pattern is used in a configuration block which also hasfiles
, then the pattern is interpreted completely differently, and does not have the same effect:Rather, to ignore the entire top-level
ignored
tree, theignores
pattern needs to be adjusted as follows:Is this difference in behavior between the two
ignores
(global and non-global) intentional? And if so, can it be explicitly documented, if not already? It seems like a surprising "gotcha".What actually happened?
Link to Minimal Reproducible Example
https://stackblitz.com/edit/eslint-ignore-pattern-inconsistency
Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: