-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathindex.ts
42 lines (36 loc) · 1.18 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { type LinterConfigRules } from '../../lib/configs';
import rules from '../../lib/rules';
import {
SUPPORTED_TESTING_FRAMEWORKS,
SupportedTestingFramework,
} from '../../lib/utils';
import { LinterConfig, writeConfig } from './utils';
const RULE_NAME_PREFIX = 'testing-library/';
const getRecommendedRulesForTestingFramework = (
framework: SupportedTestingFramework
): LinterConfigRules =>
Object.entries(rules)
.filter(
([
_,
{
meta: { docs },
},
]) => Boolean(docs.recommendedConfig[framework])
)
.reduce((allRules, [ruleName, { meta }]) => {
const name = `${RULE_NAME_PREFIX}${ruleName}`;
const recommendation = meta.docs.recommendedConfig[framework];
return {
...allRules,
[name]: recommendation,
};
}, {});
SUPPORTED_TESTING_FRAMEWORKS.forEach((framework) => {
const specificFrameworkConfig: LinterConfig = {
// "plugins" property must be assigned after defining the plugin variable in the "lib/index.ts"
// https://eslint.org/docs/latest/extend/plugin-migration-flat-config#migrating-configs-for-flat-config
rules: getRecommendedRulesForTestingFramework(framework),
};
writeConfig(specificFrameworkConfig, framework);
});