Skip to content

Commit 8e1f962

Browse files
committed
fix: trim fileExtensions entries and reject blank-only arrays
The ignore and ignoreFiles options have always been trimmed; fileExtensions was not. A leading/trailing space produced a glob like **/*. scss which matched nothing.
1 parent 207572f commit 8e1f962

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,14 @@ function parseOptions(opts) {
113113
let extensions = options.fileExtensions;
114114

115115
extensions = Array.isArray(extensions) ? extensions : [extensions];
116-
// Replace possible fullstop prefix
117-
extensions = extensions.map(ext => ext.startsWith('.') ? ext.slice(1) : ext);
118-
extensions = extensions.filter(ext => ext.length > 0);
116+
// Trim, strip a leading dot, and drop blanks
117+
extensions = extensions
118+
.map(extension => {
119+
const trimmed = extension.trim();
120+
return trimmed.startsWith('.') ? trimmed.slice(1) : trimmed;
121+
})
122+
.filter(Boolean);
123+
119124
if (extensions.length === 0) {
120125
throw new TypeError('`fileExtensions` must contain at least one non-empty extension');
121126
}

tests/api.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ test('throws TypeError when fileExtensions is an empty array', () => {
6868
}, TypeError);
6969
});
7070

71+
test('throws TypeError when fileExtensions contains only blank strings', () => {
72+
assert.throws(() => {
73+
find(fixturesDir, { fileExtensions: [' '] });
74+
}, TypeError);
75+
});
76+
77+
test('fileExtensions with surrounding whitespace is trimmed and works', () => {
78+
const result = find(fixturesDir, { fileExtensions: [' scss '] });
79+
assert.equal(result.total, 2);
80+
});
7181

7282
test('find accepts null opts without throwing', () => {
7383
const result = find(fixturesDir, null);

0 commit comments

Comments
 (0)