Skip to content

Commit a61c359

Browse files
IanVSilyavolodin
authored andcommitted
Fix: Ignore hidden folders when resolving globs (fixes #8259) (#8270)
This is a performance improvement, but should not be a change to linting functionality. This is similar to avoiding glob resolution within `node_modules`. With this change, `node-glob` will not attempt to find all files within `.dotfolder` folders. Similar to `node_modules`, this can be overridden in a user’s ignore file or in an ignore-pattern.
1 parent 6f05546 commit a61c359

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/ignored-paths.js

+6
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ class IgnoredPaths {
201201

202202
const ig = ignore().add(DEFAULT_IGNORE_DIRS);
203203

204+
if (this.options.dotfiles !== true) {
205+
206+
// Ignore hidden folders. (This cannot be ".*", or else it's not possible to unignore hidden files)
207+
ig.add([".*/*", "!../"]);
208+
}
209+
204210
if (this.options.ignore) {
205211
ig.add(this.ig.custom);
206212
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
!/node_modules/package
22
!/bower_components/package
3+
!.hidden/package

tests/lib/ignored-paths.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,10 @@ describe("IgnoredPaths", () => {
550550
assert.isTrue(shouldIgnore(resolve("bower_components/a")));
551551
assert.isTrue(shouldIgnore(resolve("bower_components/a/b")));
552552
assert.isFalse(shouldIgnore(resolve(".hidden")));
553+
assert.isTrue(shouldIgnore(resolve(".hidden/a")));
553554
});
554555

555-
it("should ignore default folders there is an ignore file without unignored defaults", () => {
556+
it("should ignore default folders when there is an ignore file without unignored defaults", () => {
556557
const cwd = getFixturePath();
557558
const ignoredPaths = new IgnoredPaths({ ignore: true, ignorePath: getFixturePath(".eslintignore"), cwd });
558559

@@ -564,6 +565,7 @@ describe("IgnoredPaths", () => {
564565
assert.isTrue(shouldIgnore(resolve("bower_components/a")));
565566
assert.isTrue(shouldIgnore(resolve("bower_components/a/b")));
566567
assert.isFalse(shouldIgnore(resolve(".hidden")));
568+
assert.isTrue(shouldIgnore(resolve(".hidden/a")));
567569
});
568570

569571
it("should not ignore things which are re-included in ignore file", () => {
@@ -578,8 +580,10 @@ describe("IgnoredPaths", () => {
578580
assert.isTrue(shouldIgnore(resolve("bower_components/a")));
579581
assert.isTrue(shouldIgnore(resolve("bower_components/a/b")));
580582
assert.isFalse(shouldIgnore(resolve(".hidden")));
583+
assert.isTrue(shouldIgnore(resolve(".hidden/a")));
581584
assert.isFalse(shouldIgnore(resolve("node_modules/package")));
582585
assert.isFalse(shouldIgnore(resolve("bower_components/package")));
586+
assert.isFalse(shouldIgnore(resolve(".hidden/package")));
583587
});
584588

585589
it("should ignore files which we try to re-include in ignore file when ignore option is disabled", () => {
@@ -594,8 +598,10 @@ describe("IgnoredPaths", () => {
594598
assert.isTrue(shouldIgnore(resolve("bower_components/a")));
595599
assert.isTrue(shouldIgnore(resolve("bower_components/a/b")));
596600
assert.isFalse(shouldIgnore(resolve(".hidden")));
601+
assert.isTrue(shouldIgnore(resolve(".hidden/a")));
597602
assert.isTrue(shouldIgnore(resolve("node_modules/package")));
598603
assert.isTrue(shouldIgnore(resolve("bower_components/package")));
604+
assert.isTrue(shouldIgnore(resolve(".hidden/package")));
599605
});
600606

601607
it("should not ignore dirs which are re-included by ignorePattern", () => {
@@ -610,9 +616,21 @@ describe("IgnoredPaths", () => {
610616
assert.isTrue(shouldIgnore(resolve("bower_components/a")));
611617
assert.isTrue(shouldIgnore(resolve("bower_components/a/b")));
612618
assert.isFalse(shouldIgnore(resolve(".hidden")));
619+
assert.isTrue(shouldIgnore(resolve(".hidden/a")));
613620
assert.isFalse(shouldIgnore(resolve("node_modules/package")));
614621
assert.isTrue(shouldIgnore(resolve("bower_components/package")));
615622
});
623+
624+
it("should not ignore hidden dirs when dotfiles is enabled", () => {
625+
const cwd = getFixturePath("no-ignore-file");
626+
const ignoredPaths = new IgnoredPaths({ ignore: true, cwd, dotfiles: true });
627+
628+
const shouldIgnore = ignoredPaths.getIgnoredFoldersGlobChecker();
629+
const resolve = createResolve(cwd);
630+
631+
assert.isFalse(shouldIgnore(resolve(".hidden")));
632+
assert.isFalse(shouldIgnore(resolve(".hidden/a")));
633+
});
616634
});
617635

618636
});

0 commit comments

Comments
 (0)