fix: normalize glob patterns for consistent file matching#550
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an inconsistency in how glob patterns were matched against normalized file paths. Previously, patterns containing leading Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly identifies a bug where glob patterns with a ./ prefix were not matching file paths as expected. The introduction of the normalizePattern function is the right approach. However, the current implementation of normalizePattern is incomplete as it doesn't handle .. path segments, which could lead to continued incorrect matching. I've provided a critical suggestion to use tspath.NormalizePath for a more robust and correct implementation. Additionally, I've included a medium-severity suggestion to improve performance by normalizing patterns only once when the configuration is loaded. Finally, I've suggested adding a test case to cover the .. scenario once normalizePattern is updated.
Config patterns like "./src/foo.ts" failed to match normalized file paths "src/foo.ts" because normalizePath strips leading "./", mid-path "/./", and resolves ".." segments, but patterns were passed to doublestar.Match as-is. Add normalizePattern() using tspath.NormalizePath to apply the same cleanup to patterns in isFileMatched, isFileIgnored, and isFileIgnoredSimple.
74b869c to
7de15e1
Compare
Summary
files/ignorespatterns with relative path segments (e.g.,"./src/foo.ts","src/./utils/*.ts","src/../lib/*.ts") failed to match normalized file paths becausenormalizePathstrips./, collapses/./, and resolves.., but patterns were passed todoublestar.Matchas-is.normalizePattern()usingtspath.NormalizePathto apply the same path cleanup to glob patterns before matching.isFileMatched,isFileIgnored, andisFileIgnoredSimple.Related Links
N/A
Checklist