Skip to content

Commit

Permalink
fix(types): fix types of flat configs
Browse files Browse the repository at this point in the history
Fixes #3878
  • Loading branch information
CHC383 committed Jan 14, 2025
1 parent e6b5b41 commit cd30752
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@ const activeRulesConfig = configureAsError(activeRules);
/** @type {Partial<typeof allRules>} */
const deprecatedRules = filterRules(allRules, (rule) => rule.meta.deprecated);

/** @type {['react']} */
// for legacy config system
const plugins = [
'react',
];
/** @typedef {['react']} Plugins */
/** @type {Plugins} */
const plugins = ['react']; // for legacy config system

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

/** @typedef {{ plugins: Plugins, rules: import('eslint').Linter.RulesRecord, parserOptions: import('eslint').Linter.ParserOptions }} ReactLegacyConfig */
/** @typedef {{ deprecatedRules: typeof deprecatedRules, rules: typeof allRules, configs: Configs }} FlatConfigPlugin */
/** @typedef {{ plugins: { react: FlatConfigPlugin }, rules: import('eslint').Linter.RulesRecord, languageOptions: { parserOptions: import('eslint').Linter.ParserOptions } }} ReactFlatConfig */
/** @typedef { "recommended"|"all"|"jsx-runtime" } ConfigKey */
/** @typedef { Record<ConfigKey, ReactFlatConfig> } FlatConfigs */
/** @typedef { Record<ConfigKey, ReactLegacyConfig> & { flat: FlatConfigs }} Configs */

/** @type { Configs } */
const configs = {
recommended: {
plugins,
Expand Down Expand Up @@ -90,21 +96,17 @@ const configs = {
'react/jsx-uses-react': SEVERITY_OFF,
},
},
flat: /** @type {Record<string, ReactFlatConfig>} */ ({
__proto__: null,
}),
flat: /** @type { FlatConfigs } */ ({}),
};

/** @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<string, ReactFlatConfig> }}} */
/** @type { FlatConfigPlugin } */
const plugin = {
deprecatedRules,
rules: allRules,
configs,
};

Object.assign(configs.flat, {
configs.flat = {
recommended: {
plugins: { react: plugin },
rules: configs.recommended.rules,
Expand All @@ -120,6 +122,6 @@ Object.assign(configs.flat, {
rules: configs['jsx-runtime'].rules,
languageOptions: { parserOptions: configs['jsx-runtime'].parserOptions },
},
});
};

module.exports = plugin;

0 comments on commit cd30752

Please sign in to comment.