Skip to content

Commit 4928d51

Browse files
mysticateaKai Cataldo
authored andcommitted
Fix: don't ignore the entry directory (fixes #12604) (#12607)
1 parent b41677a commit 4928d51

3 files changed

Lines changed: 65 additions & 6 deletions

File tree

lib/cli-engine/file-enumerator.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,6 @@ class FileEnumerator {
375375
* @private
376376
*/
377377
*_iterateFilesRecursive(directoryPath, options) {
378-
if (this._isIgnoredFile(directoryPath + path.sep, options)) {
379-
return;
380-
}
381378
debug(`Enter the directory: ${directoryPath}`);
382379
const { configArrayFactory, extensionRegExp } = internalSlotsMap.get(this);
383380

@@ -426,7 +423,20 @@ class FileEnumerator {
426423

427424
// Dive into the sub directory.
428425
} else if (options.recursive && stat && stat.isDirectory()) {
429-
yield* this._iterateFilesRecursive(filePath, options);
426+
if (!config) {
427+
config = configArrayFactory.getConfigArrayForFile(
428+
filePath,
429+
{ ignoreNotFoundError: true }
430+
);
431+
}
432+
const ignored = this._isIgnoredFile(
433+
filePath + path.sep,
434+
{ ...options, config }
435+
);
436+
437+
if (!ignored) {
438+
yield* this._iterateFilesRecursive(filePath, options);
439+
}
430440
}
431441
}
432442

tests/lib/cli-engine/cli-engine.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ describe("CLIEngine", () => {
12881288

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

12941294
it("should throw an error when all given files are ignored via ignore-pattern", () => {
@@ -3628,6 +3628,55 @@ describe("CLIEngine", () => {
36283628
assert.strictEqual(messages[0].ruleId, "no-console");
36293629
});
36303630
});
3631+
3632+
describe("don't ignore the entry directory.", () => {
3633+
const root = getFixturePath("cli-engine/dont-ignore-entry-dir");
3634+
3635+
it("'executeOnFiles(\".\")' should not load config files from outside of \".\".", () => {
3636+
CLIEngine = defineCLIEngineWithInMemoryFileSystem({
3637+
cwd: () => root,
3638+
files: {
3639+
"../.eslintrc.json": "BROKEN FILE",
3640+
".eslintrc.json": JSON.stringify({ root: true }),
3641+
"index.js": "console.log(\"hello\")"
3642+
}
3643+
}).CLIEngine;
3644+
engine = new CLIEngine();
3645+
3646+
// Don't throw "failed to load config file" error.
3647+
engine.executeOnFiles(".");
3648+
});
3649+
3650+
it("'executeOnFiles(\".\")' should not ignore '.' even if 'ignorePatterns' contains it.", () => {
3651+
CLIEngine = defineCLIEngineWithInMemoryFileSystem({
3652+
cwd: () => root,
3653+
files: {
3654+
"../.eslintrc.json": JSON.stringify({ ignorePatterns: ["/dont-ignore-entry-dir"] }),
3655+
".eslintrc.json": JSON.stringify({ root: true }),
3656+
"index.js": "console.log(\"hello\")"
3657+
}
3658+
}).CLIEngine;
3659+
engine = new CLIEngine();
3660+
3661+
// Don't throw "file not found" error.
3662+
engine.executeOnFiles(".");
3663+
});
3664+
3665+
it("'executeOnFiles(\"subdir\")' should not ignore './subdir' even if 'ignorePatterns' contains it.", () => {
3666+
CLIEngine = defineCLIEngineWithInMemoryFileSystem({
3667+
cwd: () => root,
3668+
files: {
3669+
".eslintrc.json": JSON.stringify({ ignorePatterns: ["/subdir"] }),
3670+
"subdir/.eslintrc.json": JSON.stringify({ root: true }),
3671+
"subdir/index.js": "console.log(\"hello\")"
3672+
}
3673+
}).CLIEngine;
3674+
engine = new CLIEngine();
3675+
3676+
// Don't throw "file not found" error.
3677+
engine.executeOnFiles("subdir");
3678+
});
3679+
});
36313680
});
36323681

36333682
describe("getConfigForFile", () => {

tests/lib/cli-engine/file-enumerator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ describe("FileEnumerator", () => {
380380

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

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

0 commit comments

Comments
 (0)