Skip to content

Commit

Permalink
Add name to flat configs (#2377)
Browse files Browse the repository at this point in the history
Co-authored-by: fisker Cheung <[email protected]>
  • Loading branch information
voxpelli and fisker authored Jun 14, 2024
1 parent 1490bb6 commit ac8536e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ const allRules = Object.fromEntries(
]),
);

const createConfig = (rules, isLegacyConfig = false) => ({
...(isLegacyConfig ? legacyConfigBase : flatConfigBase),
plugins: isLegacyConfig ? ['unicorn'] : {unicorn},
const createConfig = (rules, flatConfigName = false) => ({
...(
flatConfigName
? {...flatConfigBase, name: flatConfigName, plugins: {unicorn}}
: {...legacyConfigBase, plugins: ['unicorn']}
),
rules: {...externalRules, ...rules},
});

Expand All @@ -65,10 +68,10 @@ const unicorn = {
};

const configs = {
recommended: createConfig(recommendedRules, /* isLegacyConfig */ true),
all: createConfig(allRules, /* isLegacyConfig */ true),
'flat/recommended': createConfig(recommendedRules),
'flat/all': createConfig(allRules),
recommended: createConfig(recommendedRules),
all: createConfig(allRules),
'flat/recommended': createConfig(recommendedRules, 'unicorn/flat/recommended'),
'flat/all': createConfig(allRules, 'unicorn/flat/all'),
};

module.exports = {...unicorn, configs};
4 changes: 2 additions & 2 deletions test/package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ function getCompactConfig(config) {

test('flat configs', t => {
t.deepEqual(
getCompactConfig(eslintPluginUnicorn.configs.recommended),
{...getCompactConfig(eslintPluginUnicorn.configs.recommended), name: 'unicorn/flat/recommended'},
{...eslintPluginUnicorn.configs['flat/recommended'], plugins: undefined},
);
t.deepEqual(
getCompactConfig(eslintPluginUnicorn.configs.all),
{...getCompactConfig(eslintPluginUnicorn.configs.all), name: 'unicorn/flat/all'},
{...eslintPluginUnicorn.configs['flat/all'], plugins: undefined},
);
});
Expand Down

0 comments on commit ac8536e

Please sign in to comment.