Skip to content

Commit c33297f

Browse files
authored
avoid full scan with ignore empty string array (#86)
* fix: avoid full scan with ignore empty string array, fixes #85 * chore: run biome lint/format * chore: add test missing entry
1 parent f2407b4 commit c33297f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ function processPatterns(
103103
const ignorePatterns: string[] = [];
104104

105105
for (const pattern of ignore) {
106+
if (!pattern) {
107+
continue;
108+
}
106109
// don't handle negated patterns here for consistency with fast-glob
107110
if (!pattern.startsWith('!') || pattern[1] === '(') {
108111
const newPattern = normalizePattern(pattern, expandDirectories, cwd, properties, true);
@@ -112,6 +115,9 @@ function processPatterns(
112115

113116
const transformed: string[] = [];
114117
for (const pattern of patterns) {
118+
if (!pattern) {
119+
continue;
120+
}
115121
if (!pattern.startsWith('!') || pattern[1] === '(') {
116122
const newPattern = normalizePattern(pattern, expandDirectories, cwd, properties, false);
117123
matchPatterns.push(newPattern);

test/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ test('ignore option as string', async () => {
8080
assert.deepEqual(files.sort(), ['a/a.txt']);
8181
});
8282

83+
test('ignore option with an empty string array', async () => {
84+
const files = await glob({ patterns: ['**/a.txt'], ignore: [''], cwd });
85+
assert.deepEqual(files.sort(), ['a/a.txt', 'b/a.txt']);
86+
});
87+
8388
test('caseSensitiveMatch', async () => {
8489
const files = await glob({ patterns: ['**/A.TXT'], caseSensitiveMatch: false, cwd });
8590
assert.deepEqual(files.sort(), ['a/a.txt', 'b/a.txt']);

0 commit comments

Comments
 (0)