Skip to content

Commit

Permalink
Fix: Ignore hidden folders when resolving globs (fixes #8259) (#8270)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
IanVS authored and ilyavolodin committed Mar 17, 2017
1 parent 6f05546 commit a61c359
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/ignored-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ class IgnoredPaths {

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

if (this.options.dotfiles !== true) {

// Ignore hidden folders. (This cannot be ".*", or else it's not possible to unignore hidden files)
ig.add([".*/*", "!../"]);
}

if (this.options.ignore) {
ig.add(this.ig.custom);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
!/node_modules/package
!/bower_components/package
!.hidden/package
20 changes: 19 additions & 1 deletion tests/lib/ignored-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,10 @@ describe("IgnoredPaths", () => {
assert.isTrue(shouldIgnore(resolve("bower_components/a")));
assert.isTrue(shouldIgnore(resolve("bower_components/a/b")));
assert.isFalse(shouldIgnore(resolve(".hidden")));
assert.isTrue(shouldIgnore(resolve(".hidden/a")));
});

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

Expand All @@ -564,6 +565,7 @@ describe("IgnoredPaths", () => {
assert.isTrue(shouldIgnore(resolve("bower_components/a")));
assert.isTrue(shouldIgnore(resolve("bower_components/a/b")));
assert.isFalse(shouldIgnore(resolve(".hidden")));
assert.isTrue(shouldIgnore(resolve(".hidden/a")));
});

it("should not ignore things which are re-included in ignore file", () => {
Expand All @@ -578,8 +580,10 @@ describe("IgnoredPaths", () => {
assert.isTrue(shouldIgnore(resolve("bower_components/a")));
assert.isTrue(shouldIgnore(resolve("bower_components/a/b")));
assert.isFalse(shouldIgnore(resolve(".hidden")));
assert.isTrue(shouldIgnore(resolve(".hidden/a")));
assert.isFalse(shouldIgnore(resolve("node_modules/package")));
assert.isFalse(shouldIgnore(resolve("bower_components/package")));
assert.isFalse(shouldIgnore(resolve(".hidden/package")));
});

it("should ignore files which we try to re-include in ignore file when ignore option is disabled", () => {
Expand All @@ -594,8 +598,10 @@ describe("IgnoredPaths", () => {
assert.isTrue(shouldIgnore(resolve("bower_components/a")));
assert.isTrue(shouldIgnore(resolve("bower_components/a/b")));
assert.isFalse(shouldIgnore(resolve(".hidden")));
assert.isTrue(shouldIgnore(resolve(".hidden/a")));
assert.isTrue(shouldIgnore(resolve("node_modules/package")));
assert.isTrue(shouldIgnore(resolve("bower_components/package")));
assert.isTrue(shouldIgnore(resolve(".hidden/package")));
});

it("should not ignore dirs which are re-included by ignorePattern", () => {
Expand All @@ -610,9 +616,21 @@ describe("IgnoredPaths", () => {
assert.isTrue(shouldIgnore(resolve("bower_components/a")));
assert.isTrue(shouldIgnore(resolve("bower_components/a/b")));
assert.isFalse(shouldIgnore(resolve(".hidden")));
assert.isTrue(shouldIgnore(resolve(".hidden/a")));
assert.isFalse(shouldIgnore(resolve("node_modules/package")));
assert.isTrue(shouldIgnore(resolve("bower_components/package")));
});

it("should not ignore hidden dirs when dotfiles is enabled", () => {
const cwd = getFixturePath("no-ignore-file");
const ignoredPaths = new IgnoredPaths({ ignore: true, cwd, dotfiles: true });

const shouldIgnore = ignoredPaths.getIgnoredFoldersGlobChecker();
const resolve = createResolve(cwd);

assert.isFalse(shouldIgnore(resolve(".hidden")));
assert.isFalse(shouldIgnore(resolve(".hidden/a")));
});
});

});

0 comments on commit a61c359

Please sign in to comment.