Skip to content
Permalink
Browse files
Fix: Support ENOTDIR error code in the folder existence checking util…
…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 9b277a16a7261e51b7ba36d6de7f996e9203a6a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
@@ -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;
@@ -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 = {

0 comments on commit 9b277a1

Please sign in to comment.