Skip to content

Commit dc67c93

Browse files
committed
feat: add support for flat config
1 parent 3b766d1 commit dc67c93

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,5 +1,8 @@
1+
import type { TSESLint } from '@typescript-eslint/utils';
2+
13
import configs from './configs';
24
import rules from './rules';
5+
import { SupportedTestingFramework } from './utils';
36

47
// we can't natively import package.json as tsc will copy it into dist/
58
const {
@@ -8,11 +11,34 @@ const {
811
// eslint-disable-next-line @typescript-eslint/no-var-requires
912
} = require('../package.json') as { name: string; version: string };
1013

11-
export = {
14+
const plugin = {
1215
meta: {
1316
name: packageName,
1417
version: packageVersion,
1518
},
16-
configs,
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+
Pick<Required<TSESLint.Linter.Config>, 'rules'>
24+
>,
1725
rules,
1826
};
27+
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 Record<
39+
`flat/${SupportedTestingFramework}`,
40+
Pick<Required<TSESLint.Linter.Config>, 'rules'> & { plugins: unknown }
41+
>),
42+
};
43+
44+
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)