Skip to content

Commit

Permalink
Fix: ensure confg files are files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tjenkinson committed Jul 3, 2021
1 parent 593fbe3 commit 4c77284
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/config-array-factory.js
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion tests/lib/config-array-factory.js
Expand Up @@ -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": "{}"
}
});

Expand Down Expand Up @@ -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];

Expand Down

0 comments on commit 4c77284

Please sign in to comment.