Visitar URL original
Fix: Support ENOTDIR error code in the folder existence checking util… · eslint/eslint@9b277a1 · GitHub
Skip to content

Commit 9b277a1

Browse files
authored
Fix: Support ENOTDIR error code in the folder existence checking utility (#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
1 parent 7aeb127 commit 9b277a1

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎lib/cli-engine/cli-engine.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ function directoryExists(resolvedPath) {
531531
try {
532532
return fs.statSync(resolvedPath).isDirectory();
533533
} catch (error) {
534-
if (error && error.code === "ENOENT") {
534+
if (error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
535535
return false;
536536
}
537537
throw error;

‎tests/lib/eslint/eslint.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3886,6 +3886,26 @@ describe("ESLint", () => {
38863886
assert.deepStrictEqual(actualConfig, expectedConfig);
38873887
});
38883888

3889+
it("should return the config for a file that doesn't exist", async () => {
3890+
const engine = new ESLint();
3891+
const filePath = getFixturePath("does_not_exist.js");
3892+
const existingSiblingFilePath = getFixturePath("single-quoted.js");
3893+
const actualConfig = await engine.calculateConfigForFile(filePath);
3894+
const expectedConfig = await engine.calculateConfigForFile(existingSiblingFilePath);
3895+
3896+
assert.deepStrictEqual(actualConfig, expectedConfig);
3897+
});
3898+
3899+
it("should return the config for a virtual file that is a child of an existing file", async () => {
3900+
const engine = new ESLint();
3901+
const parentFileName = "single-quoted.js";
3902+
const filePath = getFixturePath(parentFileName, "virtual.js"); // single-quoted.js/virtual.js
3903+
const parentFilePath = getFixturePath(parentFileName);
3904+
const actualConfig = await engine.calculateConfigForFile(filePath);
3905+
const expectedConfig = await engine.calculateConfigForFile(parentFilePath);
3906+
3907+
assert.deepStrictEqual(actualConfig, expectedConfig);
3908+
});
38893909

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

0 commit comments

Comments
 (0)