Skip to content

Commit

Permalink
Fix: Unignoring directories in .eslintignore (fixes #11684) (#11685)
Browse files Browse the repository at this point in the history
  • Loading branch information
belochub authored and mysticatea committed May 18, 2019
1 parent 4625090 commit 5dad0b1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/cli-engine/file-enumerator.js
Expand Up @@ -380,7 +380,7 @@ class FileEnumerator {
* @private
*/
*_iterateFilesRecursive(directoryPath, options) {
if (this._isIgnoredFile(directoryPath, options)) {
if (this._isIgnoredFile(directoryPath + path.sep, options)) {
return;
}
debug(`Enter the directory: ${directoryPath}`);
Expand Down
7 changes: 6 additions & 1 deletion lib/util/ignored-paths.js
Expand Up @@ -328,12 +328,17 @@ class IgnoredPaths {
* @returns {boolean} true if the file path matches one or more patterns, false otherwise
*/
contains(filepath, category) {
const isDir = filepath.endsWith(path.sep) ||
(path.sep === "\\" && filepath.endsWith("/"));
let result = false;
const basePath = this.getBaseDir();
const absolutePath = path.resolve(this.options.cwd, filepath);
const relativePath = path.relative(basePath, absolutePath);
let relativePath = path.relative(basePath, absolutePath);

if (relativePath) {
if (isDir) {
relativePath += path.sep;
}
if (typeof category === "undefined") {
result =
(this.ig.default.filter([relativePath]).length === 0) ||
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/glob-util/unignored/.eslintignore
@@ -0,0 +1,3 @@
*
!/dir/
!*.js
Empty file.
24 changes: 24 additions & 0 deletions tests/lib/cli-engine/file-enumerator.js
Expand Up @@ -448,6 +448,30 @@ describe("FileEnumerator", () => {

assert.includeDeepMembers(result, [{ filename: unignoredFilename, ignored: false }]);
});

it("should return unignored files from folders unignored in .eslintignore", () => {
const options = { cwd: getFixturePath("glob-util", "unignored"), ignore: true };
const glob = getFixturePath("glob-util", "unignored", "**/*.js");
const patterns = [glob];
const result = listFiles(patterns, options);

const filename = getFixturePath("glob-util", "unignored", "dir", "foo.js");

assert.strictEqual(result.length, 1);
assert.deepStrictEqual(result, [{ filename, ignored: false }]);
});

it("should return unignored files from folders unignored in .eslintignore for explicitly specified folder", () => {
const options = { cwd: getFixturePath("glob-util", "unignored"), ignore: true };
const dir = getFixturePath("glob-util", "unignored", "dir");
const patterns = [dir];
const result = listFiles(patterns, options);

const filename = getFixturePath("glob-util", "unignored", "dir", "foo.js");

assert.strictEqual(result.length, 1);
assert.deepStrictEqual(result, [{ filename, ignored: false }]);
});
});
});
});
Expand Down

0 comments on commit 5dad0b1

Please sign in to comment.