Skip to content

Commit

Permalink
test: add more tests for ignoring files and directories
Browse files Browse the repository at this point in the history
Refs #17964
  • Loading branch information
mdjermanovic committed Jan 22, 2024
1 parent 60b966b commit 67cb7dd
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/fixtures/ignores-directory-deep/tests/format/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty
95 changes: 95 additions & 0 deletions tests/lib/eslint/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,101 @@ describe("ESLint", () => {
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 ESLint({
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 ESLint({
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 skip ignored files in an unignored directory", async () => {
eslint = new ESLint({
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 ESLint({
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

0 comments on commit 67cb7dd

Please sign in to comment.