diff --git a/packages/config-array/src/config-array.js b/packages/config-array/src/config-array.js index 2dce1e7..51a525b 100644 --- a/packages/config-array/src/config-array.js +++ b/packages/config-array/src/config-array.js @@ -1024,6 +1024,11 @@ export class ConfigArray extends Array { .relative(this.basePath, directoryPath) .replace(/\\/gu, "/"); + // basePath directory can never be ignored + if (relativeDirectoryPath === "") { + return false; + } + if (relativeDirectoryPath.startsWith("..")) { return true; } diff --git a/packages/config-array/tests/config-array.test.js b/packages/config-array/tests/config-array.test.js index c5270ab..11a0961 100644 --- a/packages/config-array/tests/config-array.test.js +++ b/packages/config-array/tests/config-array.test.js @@ -1071,6 +1071,64 @@ describe("ConfigArray", () => { ); }); + // https://github.com/eslint/eslint/issues/18706 + it("should disregard `/` in global `ignores`", () => { + configs = new ConfigArray( + [ + { + ignores: ["/"], + }, + { + files: ["**/*.js"], + defs: { + severity: "error", + }, + }, + ], + { basePath, schema }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfig(path.resolve(basePath, "file.js")).defs + .severity, + "error", + ); + + assert.strictEqual( + configs.getConfig( + path.resolve(basePath, "subdir", "file.js"), + ).defs.severity, + "error", + ); + }); + + it("should return config for an unignored file in basePath when all files are initially ignored by '**'", () => { + configs = new ConfigArray( + [ + { + ignores: ["**", "!file.js"], + }, + { + files: ["**/*.js"], + defs: { + severity: "error", + }, + }, + ], + { basePath, schema }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfig(path.resolve(basePath, "file.js")).defs + .severity, + "error", + ); + }); + // https://github.com/eslint/eslint/issues/17103 describe("ignores patterns should be properly applied", () => { it("should return undefined when a filename matches an ignores pattern but not a files pattern", () => { @@ -2701,6 +2759,23 @@ describe("ConfigArray", () => { ); }); + it("should always return false for basePath", () => { + configs = new ConfigArray( + [ + { + ignores: ["**", "/"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual(configs.isDirectoryIgnored(basePath), false); + }); + it("should return true when a directory is in ignores", () => { configs = new ConfigArray( [