Skip to content

Commit

Permalink
Fix: Support ENOTDIR error code in the folder existence checking util…
Browse files Browse the repository at this point in the history
…ity (#13973)

* Fix: Consider ENOTDIR error code on some platforms

GitLab CI throws ENOTDIR instead of ENOENT. Add checking for this condition.

* Chore: add tests with virtual files for ESLint#calculateConfigForFile
  • Loading branch information
constgen committed Feb 10, 2021
1 parent 7aeb127 commit 9b277a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit 9b277a1

Please sign in to comment.