Skip to content

Commit a589636

Browse files
authored
fix: Config with ignores and without files should not always apply (#17181)
* fix: Config with `ignores` and without `files` should not always apply Fixes #17103 * use @humanwhocodes/config-array@0.11.9 * use @humanwhocodes/config-array@0.11.10
1 parent 01d7142 commit a589636

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"@eslint-community/regexpp": "^4.4.0",
6565
"@eslint/eslintrc": "^2.0.3",
6666
"@eslint/js": "8.41.0",
67-
"@humanwhocodes/config-array": "^0.11.8",
67+
"@humanwhocodes/config-array": "^0.11.10",
6868
"@humanwhocodes/module-importer": "^1.0.1",
6969
"@nodelib/fs.walk": "^1.2.8",
7070
"ajv": "^6.10.0",

tests/lib/eslint/flat-eslint.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4631,6 +4631,99 @@ describe("FlatESLint", () => {
46314631
});
46324632
});
46334633

4634+
describe("configs with 'ignores' and without 'files'", () => {
4635+
4636+
// https://github.com/eslint/eslint/issues/17103
4637+
describe("config with ignores: ['error.js']", () => {
4638+
const cwd = getFixturePath("config-with-ignores-without-files");
4639+
const { prepare, cleanup, getPath } = createCustomTeardown({
4640+
cwd,
4641+
files: {
4642+
"eslint.config.js": `module.exports = [
4643+
{
4644+
rules: {
4645+
"no-unused-vars": "error",
4646+
},
4647+
},
4648+
{
4649+
ignores: ["error.js"],
4650+
rules: {
4651+
"no-unused-vars": "warn",
4652+
},
4653+
},
4654+
];`,
4655+
"error.js": "let unusedVar;",
4656+
"warn.js": "let unusedVar;"
4657+
}
4658+
});
4659+
4660+
beforeEach(prepare);
4661+
afterEach(cleanup);
4662+
4663+
it("should apply to all files except for 'error.js'", async () => {
4664+
const engine = new FlatESLint({
4665+
cwd
4666+
});
4667+
4668+
const results = await engine.lintFiles("{error,warn}.js");
4669+
4670+
assert.strictEqual(results.length, 2);
4671+
4672+
const [errorResult, warnResult] = results;
4673+
4674+
assert.strictEqual(errorResult.filePath, path.join(getPath(), "error.js"));
4675+
assert.strictEqual(errorResult.messages.length, 1);
4676+
assert.strictEqual(errorResult.messages[0].ruleId, "no-unused-vars");
4677+
assert.strictEqual(errorResult.messages[0].severity, 2);
4678+
4679+
assert.strictEqual(warnResult.filePath, path.join(getPath(), "warn.js"));
4680+
assert.strictEqual(warnResult.messages.length, 1);
4681+
assert.strictEqual(warnResult.messages[0].ruleId, "no-unused-vars");
4682+
assert.strictEqual(warnResult.messages[0].severity, 1);
4683+
});
4684+
});
4685+
4686+
describe("config with ignores: ['**/*.json']", () => {
4687+
const cwd = getFixturePath("config-with-ignores-without-files");
4688+
const { prepare, cleanup, getPath } = createCustomTeardown({
4689+
cwd,
4690+
files: {
4691+
"eslint.config.js": `module.exports = [
4692+
{
4693+
rules: {
4694+
"no-undef": "error",
4695+
},
4696+
},
4697+
{
4698+
ignores: ["**/*.json"],
4699+
rules: {
4700+
"no-unused-vars": "error",
4701+
},
4702+
},
4703+
];`,
4704+
"foo.js": "",
4705+
"foo.json": ""
4706+
}
4707+
});
4708+
4709+
beforeEach(prepare);
4710+
afterEach(cleanup);
4711+
4712+
it("should not add json files as lint targets", async () => {
4713+
const engine = new FlatESLint({
4714+
cwd
4715+
});
4716+
4717+
const results = await engine.lintFiles("foo*");
4718+
4719+
// should not lint `foo.json`
4720+
assert.strictEqual(results.length, 1);
4721+
assert.strictEqual(results[0].filePath, path.join(getPath(), "foo.js"));
4722+
});
4723+
});
4724+
4725+
});
4726+
46344727
describe("with ignores config", () => {
46354728
const root = getFixturePath("cli-engine/ignore-patterns");
46364729

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy