Skip to content

Commit

Permalink
fix: basePath directory can never be ignored (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Jul 22, 2024
1 parent 20ba992 commit c94ab2d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/config-array/src/config-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
75 changes: 75 additions & 0 deletions packages/config-array/tests/config-array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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(
[
Expand Down

0 comments on commit c94ab2d

Please sign in to comment.