Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/glob/__tests__/internal-pattern-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('pattern-helper', () => {
])
})

it('partialMatch skips negate patterns', () => {
it('partialMatch avoids going deep by respecting negate patterns', () => {
const root = IS_WINDOWS ? 'C:\\' : '/'
const patterns = [
`${root}search1/foo/**`,
Expand All @@ -143,7 +143,7 @@ describe('pattern-helper', () => {
expect(patternHelper.partialMatch(patterns, `${root}search2`)).toBeTruthy()
expect(
patternHelper.partialMatch(patterns, `${root}search2/bar`)
).toBeTruthy()
).toBeFalsy()
expect(patternHelper.partialMatch(patterns, `${root}search3`)).toBeFalsy()
expect(
patternHelper.partialMatch(patterns, `${root}search3/bar`)
Expand Down
5 changes: 4 additions & 1 deletion packages/glob/src/internal-pattern-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,8 @@ export function match(patterns: Pattern[], itemPath: string): MatchKind {
* Checks whether to descend further into the directory
*/
export function partialMatch(patterns: Pattern[], itemPath: string): boolean {
return patterns.some(x => !x.negate && x.partialMatch(itemPath))
return (
patterns.some(x => !x.negate && x.partialMatch(itemPath)) &&
!patterns.some(x => x.negate && x.match(itemPath))
)
Comment on lines +80 to +83
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider short-circuiting the evaluation by checking negate patterns first, since if any negate pattern matches, the result will be false regardless of positive patterns. This could be written as: if (patterns.some(x => x.negate && x.match(itemPath))) return false; return patterns.some(x => !x.negate && x.partialMatch(itemPath));

Suggested change
return (
patterns.some(x => !x.negate && x.partialMatch(itemPath)) &&
!patterns.some(x => x.negate && x.match(itemPath))
)
// Check negate patterns first for short-circuiting
if (patterns.some(x => x.negate && x.match(itemPath))) {
return false;
}
// Check positive patterns
return patterns.some(x => !x.negate && x.partialMatch(itemPath));

Copilot uses AI. Check for mistakes.

}