From 1a891a599dcf044181693e94a6b18114033c6107 Mon Sep 17 00:00:00 2001 From: Constantine Genchevsky Date: Fri, 1 Jan 2021 18:14:30 +0200 Subject: [PATCH 1/2] Fix: Consider ENOTDIR error code on some platforms GitLab CI throws ENOTDIR instead of ENOENT. Add checking for this condition. --- lib/cli-engine/cli-engine.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli-engine/cli-engine.js b/lib/cli-engine/cli-engine.js index 9a414061501..3fd4f5ee1e3 100644 --- a/lib/cli-engine/cli-engine.js +++ b/lib/cli-engine/cli-engine.js @@ -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; From 763afbda1b6820e25f7af9f2c55e05c4cd21969a Mon Sep 17 00:00:00 2001 From: constgen Date: Sun, 31 Jan 2021 21:37:17 +0200 Subject: [PATCH 2/2] Chore: add tests with virtual files for ESLint#calculateConfigForFile --- tests/lib/eslint/eslint.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/lib/eslint/eslint.js b/tests/lib/eslint/eslint.js index 530464ecaa1..b8a9c1d204e 100644 --- a/tests/lib/eslint/eslint.js +++ b/tests/lib/eslint/eslint.js @@ -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 = {