diff --git a/package.json b/package.json index ae6e8b35fb8..6b08af451a9 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "@eslint-community/regexpp": "^4.4.0", "@eslint/eslintrc": "^2.0.3", "@eslint/js": "8.41.0", - "@humanwhocodes/config-array": "^0.11.8", + "@humanwhocodes/config-array": "^0.11.10", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", "ajv": "^6.10.0", diff --git a/tests/lib/eslint/flat-eslint.js b/tests/lib/eslint/flat-eslint.js index 24c3ab5a6c9..b68dabc2837 100644 --- a/tests/lib/eslint/flat-eslint.js +++ b/tests/lib/eslint/flat-eslint.js @@ -4631,6 +4631,99 @@ describe("FlatESLint", () => { }); }); + describe("configs with 'ignores' and without 'files'", () => { + + // https://github.com/eslint/eslint/issues/17103 + describe("config with ignores: ['error.js']", () => { + const cwd = getFixturePath("config-with-ignores-without-files"); + const { prepare, cleanup, getPath } = createCustomTeardown({ + cwd, + files: { + "eslint.config.js": `module.exports = [ + { + rules: { + "no-unused-vars": "error", + }, + }, + { + ignores: ["error.js"], + rules: { + "no-unused-vars": "warn", + }, + }, + ];`, + "error.js": "let unusedVar;", + "warn.js": "let unusedVar;" + } + }); + + beforeEach(prepare); + afterEach(cleanup); + + it("should apply to all files except for 'error.js'", async () => { + const engine = new FlatESLint({ + cwd + }); + + const results = await engine.lintFiles("{error,warn}.js"); + + assert.strictEqual(results.length, 2); + + const [errorResult, warnResult] = results; + + assert.strictEqual(errorResult.filePath, path.join(getPath(), "error.js")); + assert.strictEqual(errorResult.messages.length, 1); + assert.strictEqual(errorResult.messages[0].ruleId, "no-unused-vars"); + assert.strictEqual(errorResult.messages[0].severity, 2); + + assert.strictEqual(warnResult.filePath, path.join(getPath(), "warn.js")); + assert.strictEqual(warnResult.messages.length, 1); + assert.strictEqual(warnResult.messages[0].ruleId, "no-unused-vars"); + assert.strictEqual(warnResult.messages[0].severity, 1); + }); + }); + + describe("config with ignores: ['**/*.json']", () => { + const cwd = getFixturePath("config-with-ignores-without-files"); + const { prepare, cleanup, getPath } = createCustomTeardown({ + cwd, + files: { + "eslint.config.js": `module.exports = [ + { + rules: { + "no-undef": "error", + }, + }, + { + ignores: ["**/*.json"], + rules: { + "no-unused-vars": "error", + }, + }, + ];`, + "foo.js": "", + "foo.json": "" + } + }); + + beforeEach(prepare); + afterEach(cleanup); + + it("should not add json files as lint targets", async () => { + const engine = new FlatESLint({ + cwd + }); + + const results = await engine.lintFiles("foo*"); + + // should not lint `foo.json` + assert.strictEqual(results.length, 1); + assert.strictEqual(results[0].filePath, path.join(getPath(), "foo.js")); + }); + }); + + }); + describe("with ignores config", () => { const root = getFixturePath("cli-engine/ignore-patterns");