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(typescript-eslint): apply ignores to all extended configs passed to config helper function #8567

Merged
merged 1 commit into from Feb 27, 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
19 changes: 11 additions & 8 deletions packages/typescript-eslint/src/config-helper.ts
Expand Up @@ -91,14 +91,17 @@ export function config(
return config;
}

if (config.files) {
const files = config.files;
return [
...extendsArr.map(conf => ({ ...conf, files: [...files] })),
config,
];
}
const extension = {
...(config.files && { files: config.files }),
...(config.ignores && { ignores: config.ignores }),
Comment on lines +95 to +96
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignores will overwrite ignores from the extended config. I'm not sure if this is the desired behavior, but so far I've made it to match the behavior of files. Any thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think overriding is correct.
Any local config should always override the extended config

};

return [...extendsArr, config];
return [
...extendsArr.map(conf => ({
...conf,
...extension,
})),
config,
];
});
}
58 changes: 58 additions & 0 deletions packages/typescript-eslint/tests/configs.test.ts
Expand Up @@ -211,3 +211,61 @@ describe('stylistic-type-checked.ts', () => {

itHasBaseRulesOverriden(unfilteredConfigRules);
});

describe('config helper', () => {
it('works without extends', () => {
expect(
plugin.config({
files: ['file'],
rules: { rule: 'error' },
ignores: ['ignored'],
}),
).toEqual([
{
files: ['file'],
rules: { rule: 'error' },
ignores: ['ignored'],
},
]);
});

it('flattens extended configs', () => {
expect(
plugin.config({
rules: { rule: 'error' },
extends: [{ rules: { rule1: 'error' } }, { rules: { rule2: 'error' } }],
}),
).toEqual([
{ rules: { rule1: 'error' } },
{ rules: { rule2: 'error' } },
{ rules: { rule: 'error' } },
]);
});

it('flattens extended configs with files and ignores', () => {
expect(
plugin.config({
files: ['common-file'],
ignores: ['common-ignored'],
rules: { rule: 'error' },
extends: [{ rules: { rule1: 'error' } }, { rules: { rule2: 'error' } }],
}),
).toEqual([
{
files: ['common-file'],
ignores: ['common-ignored'],
rules: { rule1: 'error' },
},
{
files: ['common-file'],
ignores: ['common-ignored'],
rules: { rule2: 'error' },
},
{
files: ['common-file'],
ignores: ['common-ignored'],
rules: { rule: 'error' },
},
]);
});
});