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

test: add more tests for ignoring files and directories #18068

Merged
merged 1 commit into from Feb 1, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
// empty
@@ -0,0 +1 @@
// empty
@@ -0,0 +1 @@
// empty
@@ -0,0 +1 @@
// empty
114 changes: 114 additions & 0 deletions tests/lib/eslint/flat-eslint.js
Expand Up @@ -1723,6 +1723,120 @@ describe("FlatESLint", () => {
assert.strictEqual(results[0].filePath, getFixturePath("ignores-directory/subdir/subsubdir/a.js"));
});

// https://github.com/eslint/eslint/issues/17964#issuecomment-1879840650
it("should allow directories to be unignored without also unignoring all files in them", async () => {
eslint = new FlatESLint({
cwd: getFixturePath("ignores-directory-deep"),
overrideConfigFile: true,
overrideConfig: {
ignores: [

// ignore all files and directories
"tests/format/**/*",

// unignore all directories
"!tests/format/**/*/",

// unignore only specific files
"!tests/format/**/jsfmt.spec.js"
]
}
});
const results = await eslint.lintFiles(["."]);

assert.strictEqual(results.length, 2);
assert.strictEqual(results[0].errorCount, 0);
assert.strictEqual(results[0].warningCount, 0);
assert.strictEqual(results[0].filePath, getFixturePath("ignores-directory-deep/tests/format/jsfmt.spec.js"));
assert.strictEqual(results[1].errorCount, 0);
assert.strictEqual(results[1].warningCount, 0);
assert.strictEqual(results[1].filePath, getFixturePath("ignores-directory-deep/tests/format/subdir/jsfmt.spec.js"));
});

it("should allow only subdirectories to be ignored by a pattern ending with '/'", async () => {
eslint = new FlatESLint({
cwd: getFixturePath("ignores-directory-deep"),
overrideConfigFile: true,
overrideConfig: {
ignores: [
"tests/format/*/"
]
}
});
const results = await eslint.lintFiles(["."]);

assert.strictEqual(results.length, 2);
assert.strictEqual(results[0].errorCount, 0);
assert.strictEqual(results[0].warningCount, 0);
assert.strictEqual(results[0].filePath, getFixturePath("ignores-directory-deep/tests/format/foo.js"));
assert.strictEqual(results[1].errorCount, 0);
assert.strictEqual(results[1].warningCount, 0);
assert.strictEqual(results[1].filePath, getFixturePath("ignores-directory-deep/tests/format/jsfmt.spec.js"));
});

it("should allow only contents of a directory but not the directory itself to be ignored by a pattern ending with '**/*'", async () => {
eslint = new FlatESLint({
cwd: getFixturePath("ignores-directory-deep"),
overrideConfigFile: true,
overrideConfig: {
ignores: [
"tests/format/**/*",
"!tests/format/jsfmt.spec.js"
]
}
});
const results = await eslint.lintFiles(["."]);

assert.strictEqual(results.length, 1);
assert.strictEqual(results[0].errorCount, 0);
assert.strictEqual(results[0].warningCount, 0);
assert.strictEqual(results[0].filePath, getFixturePath("ignores-directory-deep/tests/format/jsfmt.spec.js"));
});

it("should skip ignored files in an unignored directory", async () => {
eslint = new FlatESLint({
cwd: getFixturePath("ignores-directory-deep"),
overrideConfigFile: true,
overrideConfig: {
ignores: [

// ignore 'tests/format/' and all its contents
"tests/format/**",

// unignore 'tests/format/', but its contents is still ignored
"!tests/format/"
]
}
});

await assert.rejects(async () => {
await eslint.lintFiles(["."]);
}, /All files matched by '.' are ignored/u);
});

it("should skip files in an ignored directory even if they are matched by a negated pattern", async () => {
eslint = new FlatESLint({
cwd: getFixturePath("ignores-directory-deep"),
overrideConfigFile: true,
overrideConfig: {
ignores: [

// ignore 'tests/format/' and all its contents
"tests/format/**",

// this patterns match some or all of its contents, but 'tests/format/' is still ignored
"!tests/format/jsfmt.spec.js",
"!tests/format/**/jsfmt.spec.js",
"!tests/format/*",
"!tests/format/**/*"
]
}
});

await assert.rejects(async () => {
await eslint.lintFiles(["."]);
}, /All files matched by '.' are ignored/u);
});

});

Expand Down