Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 0163f31

Browse files
committed
fix: Allow directory-based ignores for files matches
1 parent 613eb73 commit 0163f31

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/config-array.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,16 @@ function shouldIgnorePath(ignores, filePath, relativeFilePath) {
204204

205205
// don't check negated patterns because we're not ignored yet
206206
if (!matcher.startsWith('!')) {
207-
return doMatch(relativeFilePath, matcher);
207+
208+
/*
209+
* In order to allow patterns such as "ignore/" to work
210+
* to ignore complete directories, we need to append "**"
211+
* at the end of any pattern that ends with a slash.
212+
* See https://github.com/eslint/eslint/issues/17213
213+
*/
214+
return matcher.endsWith('/')
215+
? doMatch(relativeFilePath, `${matcher}**`)
216+
: doMatch(relativeFilePath, matcher);
208217
}
209218

210219
// otherwise we're still not ignored

tests/config-array.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,39 @@ describe('ConfigArray', () => {
12521252
});
12531253
});
12541254

1255+
// https://github.com/eslint/eslint/issues/17213
1256+
describe('ignore entire directory', () => {
1257+
1258+
it('should return true when a subdirectory is ignored with double stars', () => {
1259+
configs = new ConfigArray([
1260+
{
1261+
files: ['**/*.js'],
1262+
ignores: ['ignored/**'],
1263+
}
1264+
], { basePath });
1265+
1266+
configs.normalizeSync();
1267+
const filename = path.resolve(basePath, 'ignored/foo.js');
1268+
1269+
expect(configs.isFileIgnored(filename)).to.be.true;
1270+
});
1271+
1272+
it('should return true when a subdirectory is ignored with trailing slash', () => {
1273+
configs = new ConfigArray([
1274+
{
1275+
files: ['**/*.js'],
1276+
ignores: ['ignored/'],
1277+
}
1278+
], { basePath });
1279+
1280+
configs.normalizeSync();
1281+
const filename = path.resolve(basePath, 'ignored/foo.js');
1282+
1283+
expect(configs.isFileIgnored(filename)).to.be.true;
1284+
});
1285+
1286+
});
1287+
12551288
});
12561289

12571290
describe('isDirectoryIgnored()', () => {

0 commit comments

Comments
 (0)