|
1 | | -import configs from './configs'; |
| 1 | +import { legacyConfigs } from './configs'; |
2 | 2 | import rules from './rules'; |
3 | 3 |
|
4 | 4 | import type { SupportedTestingFramework } from './utils'; |
5 | 5 | import type { TSESLint } from '@typescript-eslint/utils'; |
6 | 6 |
|
7 | | -// we can't natively import package.json as tsc will copy it into dist/ |
8 | 7 | const { |
9 | 8 | name: packageName, |
10 | 9 | version: packageVersion, |
| 10 | + // we can't natively import package.json as tsc will copy it into dist/ |
11 | 11 | // eslint-disable-next-line @typescript-eslint/no-require-imports |
12 | 12 | } = require('../package.json') as { name: string; version: string }; |
13 | 13 |
|
| 14 | +type FinalConfigs = Record< |
| 15 | + SupportedTestingFramework | `flat/${SupportedTestingFramework}`, |
| 16 | + TSESLint.ClassicConfig.Config | TSESLint.FlatConfig.Config |
| 17 | +>; |
| 18 | + |
14 | 19 | const plugin = { |
15 | 20 | meta: { |
16 | 21 | name: packageName, |
17 | 22 | version: packageVersion, |
18 | 23 | }, |
19 | | - // ugly cast for now to keep TypeScript happy since |
20 | | - // we don't have types for flat config yet |
21 | | - configs: {} as Record< |
22 | | - SupportedTestingFramework | `flat/${SupportedTestingFramework}`, |
23 | | - TSESLint.SharedConfig.RulesRecord |
24 | | - >, |
| 24 | + configs: {} as FinalConfigs, |
25 | 25 | rules, |
26 | 26 | }; |
27 | 27 |
|
28 | 28 | plugin.configs = { |
29 | | - ...configs, |
30 | | - ...(Object.fromEntries( |
31 | | - Object.entries(configs).map(([framework, config]) => [ |
32 | | - `flat/${framework}`, |
33 | | - { |
34 | | - plugins: { 'testing-library': plugin }, |
35 | | - rules: config.rules, |
36 | | - }, |
37 | | - ]) |
38 | | - ) as unknown as Record< |
39 | | - `flat/${SupportedTestingFramework}`, |
40 | | - TSESLint.SharedConfig.RulesRecord & { plugins: unknown } |
41 | | - >), |
42 | | -}; |
| 29 | + ...legacyConfigs, |
| 30 | + 'flat/dom': { |
| 31 | + plugins: { 'testing-library': plugin }, |
| 32 | + rules: legacyConfigs.dom.rules, |
| 33 | + }, |
| 34 | + 'flat/angular': { |
| 35 | + plugins: { 'testing-library': plugin }, |
| 36 | + rules: legacyConfigs.angular.rules, |
| 37 | + }, |
| 38 | + 'flat/react': { |
| 39 | + plugins: { 'testing-library': plugin }, |
| 40 | + rules: legacyConfigs.react.rules, |
| 41 | + }, |
| 42 | + 'flat/vue': { |
| 43 | + plugins: { 'testing-library': plugin }, |
| 44 | + rules: legacyConfigs.vue.rules, |
| 45 | + }, |
| 46 | + 'flat/svelte': { |
| 47 | + plugins: { 'testing-library': plugin }, |
| 48 | + rules: legacyConfigs.svelte.rules, |
| 49 | + }, |
| 50 | + 'flat/marko': { |
| 51 | + plugins: { 'testing-library': plugin }, |
| 52 | + rules: legacyConfigs.marko.rules, |
| 53 | + }, |
| 54 | +} satisfies FinalConfigs; |
43 | 55 |
|
44 | 56 | export = plugin; |
0 commit comments