Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: basePath directory can never be ignored #92

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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