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 4 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

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