|
4 | 4 | * This source code is licensed under the MIT license found in the |
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | */ |
7 | | -import type {Linter, Rule} from 'eslint'; |
| 7 | +import type {ESLint, Linter, Rule} from 'eslint'; |
8 | 8 |
|
9 | 9 | import ExhaustiveDeps from './rules/ExhaustiveDeps'; |
10 | 10 | import { |
@@ -55,43 +55,50 @@ const recommendedLatestRuleConfigs: Linter.RulesRecord = { |
55 | 55 | ...recommendedLatestCompilerRuleConfigs, |
56 | 56 | }; |
57 | 57 |
|
58 | | -const plugins = ['react-hooks']; |
59 | | - |
60 | | -type ReactHooksFlatConfig = { |
61 | | - plugins: {react: any}; |
62 | | - rules: Linter.RulesRecord; |
| 58 | +const pluginsLegacy = ['react-hooks']; |
| 59 | +const pluginsFlat = { |
| 60 | + 'react-hooks': {}, // Assign after creating the plugin object |
63 | 61 | }; |
64 | 62 |
|
65 | | -const configs = { |
66 | | - recommended: { |
67 | | - plugins, |
68 | | - rules: recommendedRuleConfigs, |
69 | | - }, |
70 | | - 'recommended-latest': { |
71 | | - plugins, |
72 | | - rules: recommendedLatestRuleConfigs, |
73 | | - }, |
74 | | - flat: {} as Record<string, ReactHooksFlatConfig>, |
75 | | -}; |
| 63 | +interface Plugin extends Omit<ESLint.Plugin, 'configs'> { |
| 64 | + configs: { |
| 65 | + recommended: Linter.LegacyConfig; |
| 66 | + 'recommended-latest': Linter.LegacyConfig; |
| 67 | + flat: { |
| 68 | + recommended: Linter.Config; |
| 69 | + 'recommended-latest': Linter.Config; |
| 70 | + }; |
| 71 | + }; |
| 72 | +} |
76 | 73 |
|
77 | 74 | const plugin = { |
78 | 75 | meta: { |
79 | 76 | name: 'eslint-plugin-react-hooks', |
80 | 77 | version: '7.0.0', |
81 | 78 | }, |
82 | 79 | rules, |
83 | | - configs, |
84 | | -}; |
85 | | - |
86 | | -Object.assign(configs.flat, { |
87 | | - 'recommended-latest': { |
88 | | - plugins: {'react-hooks': plugin}, |
89 | | - rules: configs['recommended-latest'].rules, |
| 80 | + configs: { |
| 81 | + recommended: { |
| 82 | + plugins: pluginsLegacy, |
| 83 | + rules: recommendedRuleConfigs, |
| 84 | + }, |
| 85 | + 'recommended-latest': { |
| 86 | + plugins: pluginsLegacy, |
| 87 | + rules: recommendedLatestRuleConfigs, |
| 88 | + }, |
| 89 | + flat: { |
| 90 | + recommended: { |
| 91 | + plugins: pluginsFlat, |
| 92 | + rules: recommendedRuleConfigs, |
| 93 | + }, |
| 94 | + 'recommended-latest': { |
| 95 | + plugins: pluginsFlat, |
| 96 | + rules: recommendedLatestRuleConfigs, |
| 97 | + }, |
| 98 | + }, |
90 | 99 | }, |
91 | | - recommended: { |
92 | | - plugins: {'react-hooks': plugin}, |
93 | | - rules: configs.recommended.rules, |
94 | | - }, |
95 | | -}); |
| 100 | +} satisfies Plugin; |
| 101 | + |
| 102 | +pluginsFlat['react-hooks'] = plugin; |
96 | 103 |
|
97 | 104 | export default plugin; |
0 commit comments