Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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