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: Config with ignores and without files should not always apply #17181

Merged
merged 3 commits into from Jun 2, 2023
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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
93 changes: 93 additions & 0 deletions tests/lib/eslint/flat-eslint.js
Expand Up @@ -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);
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
assert.strictEqual(results[0].filePath, path.join(getPath(), "foo.js"));
});
});

});

describe("with ignores config", () => {
const root = getFixturePath("cli-engine/ignore-patterns");

Expand Down