Skip to content
Permalink
Browse files

Fix: don't ignore the entry directory (fixes #12604) (#12607)

  • Loading branch information
mysticatea authored and kaicataldo committed Nov 30, 2019
1 parent b41677a commit 4928d513b4fe716c7ed958c294a10ef8517be25e
Showing with 65 additions and 6 deletions.
  1. +14 −4 lib/cli-engine/file-enumerator.js
  2. +50 −1 tests/lib/cli-engine/cli-engine.js
  3. +1 −1 tests/lib/cli-engine/file-enumerator.js
@@ -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);

@@ -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);
}
}
}

@@ -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", () => {
@@ -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", () => {
@@ -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", () => {

0 comments on commit 4928d51

Please sign in to comment.
You can’t perform that action at this time.