Skip to content

Commit

Permalink
Fix: don't ignore the entry directory (fixes #12604) (#12607)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored and kaicataldo committed Nov 30, 2019
1 parent b41677a commit 4928d51
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
18 changes: 14 additions & 4 deletions lib/cli-engine/file-enumerator.js
Expand Up @@ -375,9 +375,6 @@ class FileEnumerator {
* @private
*/
*_iterateFilesRecursive(directoryPath, options) {
if (this._isIgnoredFile(directoryPath + path.sep, options)) {
return;
}
debug(`Enter the directory: ${directoryPath}`);
const { configArrayFactory, extensionRegExp } = internalSlotsMap.get(this);

Expand Down Expand Up @@ -426,7 +423,20 @@ class FileEnumerator {

// Dive into the sub directory.
} else if (options.recursive && stat && stat.isDirectory()) {
yield* this._iterateFilesRecursive(filePath, options);
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
{ ignoreNotFoundError: true }
);
}
const ignored = this._isIgnoredFile(
filePath + path.sep,
{ ...options, config }
);

if (!ignored) {
yield* this._iterateFilesRecursive(filePath, options);
}
}
}

Expand Down
51 changes: 50 additions & 1 deletion tests/lib/cli-engine/cli-engine.js
Expand Up @@ -1288,7 +1288,7 @@ describe("CLIEngine", () => {

assert.throws(() => {
engine.executeOnFiles(["./tests/fixtures/cli-engine/"]);
}, "No files matching './tests/fixtures/cli-engine/' were found.");
}, "All files matched by './tests/fixtures/cli-engine/' are ignored.");
});

it("should throw an error when all given files are ignored via ignore-pattern", () => {
Expand Down Expand Up @@ -3628,6 +3628,55 @@ describe("CLIEngine", () => {
assert.strictEqual(messages[0].ruleId, "no-console");
});
});

describe("don't ignore the entry directory.", () => {
const root = getFixturePath("cli-engine/dont-ignore-entry-dir");

it("'executeOnFiles(\".\")' should not load config files from outside of \".\".", () => {
CLIEngine = defineCLIEngineWithInMemoryFileSystem({
cwd: () => root,
files: {
"../.eslintrc.json": "BROKEN FILE",
".eslintrc.json": JSON.stringify({ root: true }),
"index.js": "console.log(\"hello\")"
}
}).CLIEngine;
engine = new CLIEngine();

// Don't throw "failed to load config file" error.
engine.executeOnFiles(".");
});

it("'executeOnFiles(\".\")' should not ignore '.' even if 'ignorePatterns' contains it.", () => {
CLIEngine = defineCLIEngineWithInMemoryFileSystem({
cwd: () => root,
files: {
"../.eslintrc.json": JSON.stringify({ ignorePatterns: ["/dont-ignore-entry-dir"] }),
".eslintrc.json": JSON.stringify({ root: true }),
"index.js": "console.log(\"hello\")"
}
}).CLIEngine;
engine = new CLIEngine();

// Don't throw "file not found" error.
engine.executeOnFiles(".");
});

it("'executeOnFiles(\"subdir\")' should not ignore './subdir' even if 'ignorePatterns' contains it.", () => {
CLIEngine = defineCLIEngineWithInMemoryFileSystem({
cwd: () => root,
files: {
".eslintrc.json": JSON.stringify({ ignorePatterns: ["/subdir"] }),
"subdir/.eslintrc.json": JSON.stringify({ root: true }),
"subdir/index.js": "console.log(\"hello\")"
}
}).CLIEngine;
engine = new CLIEngine();

// Don't throw "file not found" error.
engine.executeOnFiles("subdir");
});
});
});

describe("getConfigForFile", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/cli-engine/file-enumerator.js
Expand Up @@ -380,7 +380,7 @@ describe("FileEnumerator", () => {

assert.throws(() => {
listFiles(patterns);
}, `No files matching '${patterns[0]}' were found.`);
}, `All files matched by '${patterns[0]}' are ignored.`);
});

it("should return an ignored file, if ignore option is turned off", () => {
Expand Down

0 comments on commit 4928d51

Please sign in to comment.