From 4c7728421c698a84cf12a9779062fa11aaebe148 Mon Sep 17 00:00:00 2001 From: Tom Jenkinson Date: Sat, 3 Jul 2021 16:13:44 +0100 Subject: [PATCH] Fix: ensure confg files are files Currently if a directory name matches a config file it will be treated as a file and then fail later when we try and read it. --- lib/config-array-factory.js | 2 +- tests/lib/config-array-factory.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/config-array-factory.js b/lib/config-array-factory.js index c7ff6a09..406601c2 100644 --- a/lib/config-array-factory.js +++ b/lib/config-array-factory.js @@ -495,7 +495,7 @@ class ConfigArrayFactory { basePath ); - if (fs.existsSync(ctx.filePath)) { + if (fs.existsSync(ctx.filePath) && fs.statSync(ctx.filePath).isFile()) { let configData; try { diff --git a/tests/lib/config-array-factory.js b/tests/lib/config-array-factory.js index dff13027..8f4a29ef 100644 --- a/tests/lib/config-array-factory.js +++ b/tests/lib/config-array-factory.js @@ -269,7 +269,8 @@ describe("ConfigArrayFactory", () => { files: { ...basicFiles, "invalid-property/.eslintrc.json": "{ \"files\": \"*.js\" }", - "package-json-no-config/package.json": "{ \"name\": \"foo\" }" + "package-json-no-config/package.json": "{ \"name\": \"foo\" }", + "package-json-dir/package.json/something": "{}" } }); @@ -301,6 +302,12 @@ describe("ConfigArrayFactory", () => { }, /Unexpected top-level property "files"/u); }); + it("should ignore directories that have the same name as a config file,", () => { + const configArray = factory.loadInDirectory("package-json-dir"); + + assert.strictEqual(configArray.length, 0); + }); + for (const filePath of Object.keys(basicFiles)) { const directoryPath = filePath.split("/")[0];