From 18a0c4876e36c28be11e50ac36f25c3fbd1d74a7 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Thu, 13 Jun 2024 15:41:46 +0200 Subject: [PATCH 1/4] Add name to flat configs See https://eslint.org/docs/latest/use/configure/configuration-files#configuration-naming-conventions and eg https://github.com/eslint-community/eslint-plugin-eslint-plugin/pull/459 Improves presentation in the config inspector: https://github.com/eslint/config-inspector --- index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 0f754a2077..aebe120d69 100644 --- a/index.js +++ b/index.js @@ -47,9 +47,10 @@ const allRules = Object.fromEntries( ]), ); -const createConfig = (rules, isLegacyConfig = false) => ({ - ...(isLegacyConfig ? legacyConfigBase : flatConfigBase), - plugins: isLegacyConfig ? ['unicorn'] : {unicorn}, +const createConfig = (rules, flatConfigName = false) => ({ + ...(flatConfigName ? flatConfigBase : legacyConfigBase), + ...flatConfigName && {name: flatConfigName}, + plugins: flatConfigName ? {unicorn} : ['unicorn'], rules: {...externalRules, ...rules}, }); @@ -65,10 +66,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}; From b6b05d5d8ebd88432348cdf6aa5b5b2ce40d38fe Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Thu, 13 Jun 2024 16:06:56 +0200 Subject: [PATCH 2/4] Fix tests --- test/package.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/package.mjs b/test/package.mjs index 2dad8894fd..33cd39cfe9 100644 --- a/test/package.mjs +++ b/test/package.mjs @@ -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}, ); }); From 03d8d48a7a82994af7ab6955c192303d18285b34 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Thu, 13 Jun 2024 16:21:51 +0200 Subject: [PATCH 3/4] Update index.js Co-authored-by: fisker Cheung --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index aebe120d69..7a2855e878 100644 --- a/index.js +++ b/index.js @@ -48,9 +48,11 @@ const allRules = Object.fromEntries( ); const createConfig = (rules, flatConfigName = false) => ({ - ...(flatConfigName ? flatConfigBase : legacyConfigBase), - ...flatConfigName && {name: flatConfigName}, - plugins: flatConfigName ? {unicorn} : ['unicorn'], + ...( + flatConfigName + ? {...flatConfigBase, name: flatConfigName, plugins: {unicorn}} + : {...legacyConfigBase, plugins: ['unicorn']} + ), rules: {...externalRules, ...rules}, }); From 4201b64edad089f85f4d6715a391c27652d02248 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Thu, 13 Jun 2024 17:18:42 +0200 Subject: [PATCH 4/4] Fix linting --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7a2855e878..77bc1b1a42 100644 --- a/index.js +++ b/index.js @@ -50,8 +50,8 @@ const allRules = Object.fromEntries( const createConfig = (rules, flatConfigName = false) => ({ ...( flatConfigName - ? {...flatConfigBase, name: flatConfigName, plugins: {unicorn}} - : {...legacyConfigBase, plugins: ['unicorn']} + ? {...flatConfigBase, name: flatConfigName, plugins: {unicorn}} + : {...legacyConfigBase, plugins: ['unicorn']} ), rules: {...externalRules, ...rules}, });