From c51432e903d9b42a75aaefbcd93e88296c6985d3 Mon Sep 17 00:00:00 2001 From: Henry Cai Date: Tue, 14 Jan 2025 12:35:30 -0800 Subject: [PATCH 1/2] fix(types): fix types of flat configs Fixes #3878 --- index.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 64ff9bbdc4..31de1b8161 100644 --- a/index.js +++ b/index.js @@ -27,14 +27,14 @@ const deprecatedRules = filterRules(allRules, (rule) => rule.meta.deprecated); /** @type {['react']} */ // for legacy config system -const plugins = [ - 'react', -]; +const plugins = ['react']; // TODO: with TS 4.5+, inline this const SEVERITY_ERROR = /** @type {2} */ (2); const SEVERITY_OFF = /** @type {0} */ (0); +/** @typedef {'recommended' | 'all' | 'jsx-runtime'} AvailableFlatConfigs */ + const configs = { recommended: { plugins, @@ -90,21 +90,19 @@ const configs = { 'react/jsx-uses-react': SEVERITY_OFF, }, }, - flat: /** @type {Record} */ ({ - __proto__: null, - }), + flat: /** @type {{Record}} */ ({}), }; -/** @typedef {{ plugins: { react: typeof plugin }, rules: import('eslint').Linter.RulesRecord, languageOptions: { parserOptions: import('eslint').Linter.ParserOptions } }} ReactFlatConfig */ +/** @typedef {{plugins: {react: typeof plugin}, rules: import('eslint').Linter.RulesRecord, languageOptions: {parserOptions: import('eslint').Linter.ParserOptions}}} ReactFlatConfig */ -/** @type {{ deprecatedRules: typeof deprecatedRules, rules: typeof allRules, configs: typeof configs & { flat: Record }}} */ +/** @type {{deprecatedRules: typeof deprecatedRules, rules: typeof allRules, configs: typeof configs}}} */ const plugin = { deprecatedRules, rules: allRules, configs, }; -Object.assign(configs.flat, { +configs.flat = { recommended: { plugins: { react: plugin }, rules: configs.recommended.rules, @@ -120,6 +118,6 @@ Object.assign(configs.flat, { rules: configs['jsx-runtime'].rules, languageOptions: { parserOptions: configs['jsx-runtime'].parserOptions }, }, -}); +}; module.exports = plugin; From 2236728769129758a18ef6ed5d7cd6cb38256ad7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 14 Jan 2025 13:09:37 -0800 Subject: [PATCH 2/2] wip --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 31de1b8161..8021c2ffb6 100644 --- a/index.js +++ b/index.js @@ -90,7 +90,7 @@ const configs = { 'react/jsx-uses-react': SEVERITY_OFF, }, }, - flat: /** @type {{Record}} */ ({}), + flat: /** @type {{ [k in AvailableFlatConfigs]: ReactFlatConfig }} */ ({}), }; /** @typedef {{plugins: {react: typeof plugin}, rules: import('eslint').Linter.RulesRecord, languageOptions: {parserOptions: import('eslint').Linter.ParserOptions}}} ReactFlatConfig */ @@ -102,6 +102,7 @@ const plugin = { configs, }; +/** @type {{ [k in AvailableFlatConfigs]: ReactFlatConfig }} */ configs.flat = { recommended: { plugins: { react: plugin },