Skip to content

Commit cd30752

Browse files
committed
fix(types): fix types of flat configs
Fixes #3878
1 parent e6b5b41 commit cd30752

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

index.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@ const activeRulesConfig = configureAsError(activeRules);
2525
/** @type {Partial<typeof allRules>} */
2626
const deprecatedRules = filterRules(allRules, (rule) => rule.meta.deprecated);
2727

28-
/** @type {['react']} */
29-
// for legacy config system
30-
const plugins = [
31-
'react',
32-
];
28+
/** @typedef {['react']} Plugins */
29+
/** @type {Plugins} */
30+
const plugins = ['react']; // for legacy config system
3331

3432
// TODO: with TS 4.5+, inline this
3533
const SEVERITY_ERROR = /** @type {2} */ (2);
3634
const SEVERITY_OFF = /** @type {0} */ (0);
3735

36+
/** @typedef {{ plugins: Plugins, rules: import('eslint').Linter.RulesRecord, parserOptions: import('eslint').Linter.ParserOptions }} ReactLegacyConfig */
37+
/** @typedef {{ deprecatedRules: typeof deprecatedRules, rules: typeof allRules, configs: Configs }} FlatConfigPlugin */
38+
/** @typedef {{ plugins: { react: FlatConfigPlugin }, rules: import('eslint').Linter.RulesRecord, languageOptions: { parserOptions: import('eslint').Linter.ParserOptions } }} ReactFlatConfig */
39+
/** @typedef { "recommended"|"all"|"jsx-runtime" } ConfigKey */
40+
/** @typedef { Record<ConfigKey, ReactFlatConfig> } FlatConfigs */
41+
/** @typedef { Record<ConfigKey, ReactLegacyConfig> & { flat: FlatConfigs }} Configs */
42+
43+
/** @type { Configs } */
3844
const configs = {
3945
recommended: {
4046
plugins,
@@ -90,21 +96,17 @@ const configs = {
9096
'react/jsx-uses-react': SEVERITY_OFF,
9197
},
9298
},
93-
flat: /** @type {Record<string, ReactFlatConfig>} */ ({
94-
__proto__: null,
95-
}),
99+
flat: /** @type { FlatConfigs } */ ({}),
96100
};
97101

98-
/** @typedef {{ plugins: { react: typeof plugin }, rules: import('eslint').Linter.RulesRecord, languageOptions: { parserOptions: import('eslint').Linter.ParserOptions } }} ReactFlatConfig */
99-
100-
/** @type {{ deprecatedRules: typeof deprecatedRules, rules: typeof allRules, configs: typeof configs & { flat: Record<string, ReactFlatConfig> }}} */
102+
/** @type { FlatConfigPlugin } */
101103
const plugin = {
102104
deprecatedRules,
103105
rules: allRules,
104106
configs,
105107
};
106108

107-
Object.assign(configs.flat, {
109+
configs.flat = {
108110
recommended: {
109111
plugins: { react: plugin },
110112
rules: configs.recommended.rules,
@@ -120,6 +122,6 @@ Object.assign(configs.flat, {
120122
rules: configs['jsx-runtime'].rules,
121123
languageOptions: { parserOptions: configs['jsx-runtime'].parserOptions },
122124
},
123-
});
125+
};
124126

125127
module.exports = plugin;

0 commit comments

Comments
 (0)