Skip to content

Commit 349f2c8

Browse files
committed
feat: add support for flat config
1 parent 273cea2 commit 349f2c8

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

Diff for: lib/configs/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SupportedTestingFramework,
99
} from '../utils';
1010

11-
export type LinterConfigRules = Record<string, TSESLint.Linter.RuleEntry>;
11+
export type LinterConfigRules = Pick<Required<TSESLint.Linter.Config>, 'rules'>;
1212

1313
const configsDir = __dirname;
1414

Diff for: lib/index.ts

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
1+
import type { TSESLint } from '@typescript-eslint/utils';
2+
13
import {
24
name as packageName,
35
version as packageVersion,
46
} from '../package.json';
57

68
import configs from './configs';
79
import rules from './rules';
10+
import { SupportedTestingFramework } from './utils';
811

9-
export = {
12+
const plugin = {
1013
meta: {
1114
name: packageName,
1215
version: packageVersion,
1316
},
14-
configs,
17+
// ugly cast for now to keep TypeScript happy since
18+
// we don't have types for flat config yet
19+
configs: {} as Record<
20+
SupportedTestingFramework | `flat/${SupportedTestingFramework}`,
21+
Pick<Required<TSESLint.Linter.Config>, 'rules'>
22+
>,
1523
rules,
1624
};
25+
26+
plugin.configs = {
27+
...configs,
28+
...(Object.fromEntries(
29+
Object.entries(configs).map(([framework, config]) => [
30+
`flat/${framework}`,
31+
{
32+
plugins: { 'testing-library': plugin },
33+
rules: config.rules,
34+
},
35+
])
36+
) as Record<
37+
`flat/${SupportedTestingFramework}`,
38+
Pick<Required<TSESLint.Linter.Config>, 'rules'> & { plugins: unknown }
39+
>),
40+
};
41+
42+
export = plugin;

Diff for: tests/index.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ it('should export configs that refer to actual rules', () => {
5252
'react',
5353
'vue',
5454
'marko',
55+
'flat/dom',
56+
'flat/angular',
57+
'flat/react',
58+
'flat/vue',
59+
'flat/marko',
5560
]);
5661
const allConfigRules = Object.values(allConfigs)
5762
.map((config) => Object.keys(config.rules))

0 commit comments

Comments
 (0)