Skip to content

Commit c51432e

Browse files
committed
fix(types): fix types of flat configs
Fixes jsx-eslint#3878
1 parent e6b5b41 commit c51432e

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

index.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ const deprecatedRules = filterRules(allRules, (rule) => rule.meta.deprecated);
2727

2828
/** @type {['react']} */
2929
// for legacy config system
30-
const plugins = [
31-
'react',
32-
];
30+
const plugins = ['react'];
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 {'recommended' | 'all' | 'jsx-runtime'} AvailableFlatConfigs */
37+
3838
const configs = {
3939
recommended: {
4040
plugins,
@@ -90,21 +90,19 @@ const configs = {
9090
'react/jsx-uses-react': SEVERITY_OFF,
9191
},
9292
},
93-
flat: /** @type {Record<string, ReactFlatConfig>} */ ({
94-
__proto__: null,
95-
}),
93+
flat: /** @type {{Record<AvailableFlatConfigs, ReactFlatConfig>}} */ ({}),
9694
};
9795

98-
/** @typedef {{ plugins: { react: typeof plugin }, rules: import('eslint').Linter.RulesRecord, languageOptions: { parserOptions: import('eslint').Linter.ParserOptions } }} ReactFlatConfig */
96+
/** @typedef {{plugins: {react: typeof plugin}, rules: import('eslint').Linter.RulesRecord, languageOptions: {parserOptions: import('eslint').Linter.ParserOptions}}} ReactFlatConfig */
9997

100-
/** @type {{ deprecatedRules: typeof deprecatedRules, rules: typeof allRules, configs: typeof configs & { flat: Record<string, ReactFlatConfig> }}} */
98+
/** @type {{deprecatedRules: typeof deprecatedRules, rules: typeof allRules, configs: typeof configs}}} */
10199
const plugin = {
102100
deprecatedRules,
103101
rules: allRules,
104102
configs,
105103
};
106104

107-
Object.assign(configs.flat, {
105+
configs.flat = {
108106
recommended: {
109107
plugins: { react: plugin },
110108
rules: configs.recommended.rules,
@@ -120,6 +118,6 @@ Object.assign(configs.flat, {
120118
rules: configs['jsx-runtime'].rules,
121119
languageOptions: { parserOptions: configs['jsx-runtime'].parserOptions },
122120
},
123-
});
121+
};
124122

125123
module.exports = plugin;

0 commit comments

Comments
 (0)