Skip to content

fix(typescript-eslint): apply ignores to all extended configs passed to config helper function #8567

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions packages/typescript-eslint/src/config-helper.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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' },
},
]);
});
});
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