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: Support ENOTDIR error code in the folder existence checking utility #13973

Merged
merged 2 commits into from Feb 10, 2021
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
2 changes: 1 addition & 1 deletion lib/cli-engine/cli-engine.js
Expand Up @@ -531,7 +531,7 @@ function directoryExists(resolvedPath) {
try {
return fs.statSync(resolvedPath).isDirectory();
} catch (error) {
if (error && error.code === "ENOENT") {
if (error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
return false;
}
throw error;
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/eslint/eslint.js
Expand Up @@ -3886,6 +3886,26 @@ describe("ESLint", () => {
assert.deepStrictEqual(actualConfig, expectedConfig);
});

it("should return the config for a file that doesn't exist", async () => {
const engine = new ESLint();
const filePath = getFixturePath("does_not_exist.js");
const existingSiblingFilePath = getFixturePath("single-quoted.js");
const actualConfig = await engine.calculateConfigForFile(filePath);
const expectedConfig = await engine.calculateConfigForFile(existingSiblingFilePath);

assert.deepStrictEqual(actualConfig, expectedConfig);
});

it("should return the config for a virtual file that is a child of an existing file", async () => {
const engine = new ESLint();
const parentFileName = "single-quoted.js";
const filePath = getFixturePath(parentFileName, "virtual.js"); // single-quoted.js/virtual.js
const parentFilePath = getFixturePath(parentFileName);
const actualConfig = await engine.calculateConfigForFile(filePath);
const expectedConfig = await engine.calculateConfigForFile(parentFilePath);

assert.deepStrictEqual(actualConfig, expectedConfig);
});

it("should return the config when run from within a subdir", async () => {
const options = {
Expand Down