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

fix: match glob logic for unignore ignores #115

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

yidingww
Copy link

fix #114

The logic of getMatchedGlobs needs to be updated:

If an unignore glob is matched, and if this glob without the ! matches any previous ignore globs, all these globs should be unmatched.

@eslint-github-bot
Copy link

Hi @yidingww!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

Copy link

linux-foundation-easycla bot commented Dec 25, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@yidingww yidingww changed the title fix #114: match glob logic for negate ignores fix: match glob logic for negate ignores Dec 25, 2024
@eslint-github-bot eslint-github-bot bot added the bug Something isn't working label Dec 25, 2024
@yidingww yidingww marked this pull request as ready for review December 25, 2024 12:14
@yidingww
Copy link
Author

Probably a duplicate of #109, but i do hope you can take a look at this one as well @antfu

@yidingww yidingww changed the title fix: match glob logic for negate ignores fix: match glob logic for unignore ignores Dec 25, 2024
}
})

return flatGlobs.filter(glob => !unmatched.includes(glob))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the order of ignore and unignore might matter how it work. For the must accurate result, we might need to vendor ESLint's walker here: https://github.com/eslint/eslint/blob/5db226f4da9ad7d53a4505a90290b68d4036c082/lib/eslint/eslint-helpers.js#L216

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antfu I just updated the PR

I took a different approach, cos i realised that @eslint/config-array has a very convenient isFileIgnored here, we can use this to decide if a file is ignored, and that should fix the issue entirely.

I don't think we need to vendor the eslint-helper since it's not exported and there are a long chain of dependencies in eslint's implementations.

Comment on lines 58 to 59
// push negative globs except for unignore globs
result.globs.push(...negative.filter(glob => !glob.startsWith('!')))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might also want to push negative unignore globs here, basically all matched globs. There's a comment here where I made that switch, and I think including them causes the UI to be more clear to the user since it indicates that the globs matched, and the user can then interpret the "matched-unignore" (vs the unclear/inconsistent greyed out ui that implies it didn't match glob-wise)

// only include ignores because of how ConfigArray works internally:
// isFileIgnored only works when only `ignore` exists
// (https://github.com/eslint/rewrite/blob/config-array-v0.19.1/packages/config-array/src/config-array.js#L726)
ignores: config.ignores ?? [],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antfu @comp615 Hi guys, I just updated the PR again here in this commit

On a special note, here in particular, we need to check the current config as well to make sure the file is not ignored in current config. See inline code comment for more details

@comp615
Copy link

comp615 commented Dec 28, 2024 via email

@yidingww
Copy link
Author

@comp615 I cherry picked your commits over, and updated the solution again, now should be quite accurate

* @type {Set<string>}
*/
-const META_FIELDS = new Set(["name"]);
+const META_FIELDS = new Set(["name", "index"]);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch here is for @eslint/config-array to work as expected. Currently @eslint/config-array doesn't allow custome META_FIELDS so a patch is needed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the riskiest part of the PR. As a library maintainer, I probably wouldn't allow it. As a user, I'm all for it :-P

It looks like the upstream PR was closed here: eslint/rewrite#144, so I think it's important to make sure that there's actually a path towards the main-line using this approach. if that author refuses to allow something like this, then we're probably screwed here and need to find a different approach.

@antfu
Copy link
Collaborator

antfu commented Dec 30, 2024

Thanks for both of your hard works! @comp615 @yidingww

This implementation looks more solid to me, @comp615 do you mind me taking this inside of #109? Or do you have any thing to add?

@@ -339,7 +339,7 @@ onMounted(async () => {
<div>Ignored by globs:</div>
<div flex="~ gap-2 items-center wrap">
<GlobItem
v-for="glob, idx of fileMatchResult.globs"
v-for="glob, idx of fileMatchResult.globs.filter(glob => !glob.startsWith('!'))"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want to show negative globs here, they are part of the match so again we can let the user figure them out. I think it's most helpful to show everything that matches (positive or negative)

* @type {Set<string>}
*/
-const META_FIELDS = new Set(["name"]);
+const META_FIELDS = new Set(["name", "index"]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the riskiest part of the PR. As a library maintainer, I probably wouldn't allow it. As a user, I'm all for it :-P

It looks like the upstream PR was closed here: eslint/rewrite#144, so I think it's important to make sure that there's actually a path towards the main-line using this approach. if that author refuses to allow something like this, then we're probably screwed here and need to find a different approach.

Comment on lines +20 to +24
return globs.filter((glob) => {
const matchResult = minimatch(file, glob)
// for unignore glob, we need to flip back the match
return glob.startsWith('!') ? !matchResult : matchResult
}).flat()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMPORTANT: Instead of doing this, see my patch where you should should add flipNegate: true to the minimatchOpts

@comp615
Copy link

comp615 commented Jan 2, 2025

Thanks for both of your hard works! @comp615 @yidingww

This implementation looks more solid to me, @comp615 do you mind me taking this inside of #109? Or do you have any thing to add?

Agree that using the actual config files is a more directly and reliable way to match. I don't know the history here, but I assume something like the metadata issue is why it wasn't done this way in the first place? Or perhaps because it seems duplicative to match, and then match globs again anyways.

I left a little bit of feedback to clean it up; if I were you, I'd just want to make sure that there's a path forward to removing the "patch" of config-array. But otherwise I think this is great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Test matching with filepath..." not working with unignore glob pattern
3 participants