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 b7ad705
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -90,21 +90,19 @@ const configs = {
'react/jsx-uses-react': SEVERITY_OFF,
},
},
flat: /** @type {Record<string, ReactFlatConfig>} */ ({
__proto__: null,
}),
flat: /** @type { Record<AvailableFlatConfigs, 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<string, ReactFlatConfig> }}} */
/** @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,
Expand All @@ -120,6 +118,6 @@ Object.assign(configs.flat, {
rules: configs['jsx-runtime'].rules,
languageOptions: { parserOptions: configs['jsx-runtime'].parserOptions },
},
});
};

module.exports = plugin;

0 comments on commit b7ad705

Please sign in to comment.