|
1 | 1 | import { readdirSync } from 'fs'; |
2 | 2 | import { join, parse } from 'path'; |
3 | 3 | import { TSESLint, TSESTree } from '@typescript-eslint/utils'; |
| 4 | +import { |
| 5 | + name as packageName, |
| 6 | + version as packageVersion, |
| 7 | +} from '../package.json'; |
4 | 8 |
|
5 | 9 | type RuleModule = TSESLint.RuleModule<string, unknown[]> & { |
6 | 10 | meta: Required<Pick<TSESLint.RuleMetaData<string>, 'docs'>>; |
@@ -68,15 +72,34 @@ const allRules = Object.entries(rules) |
68 | 72 | {}, |
69 | 73 | ); |
70 | 74 |
|
71 | | -const createConfig = (rules: Record<string, TSESLint.Linter.RuleLevel>) => ({ |
| 75 | +const plugin = { |
| 76 | + meta: { name: packageName, version: packageVersion }, |
| 77 | + // ugly cast for now to keep TypeScript happy since |
| 78 | + // we don't have types for flat config yet |
| 79 | + configs: {} as Record< |
| 80 | + 'all' | 'recommended' | 'flat/all' | 'flat/recommended', |
| 81 | + Pick<Required<TSESLint.Linter.Config>, 'rules'> |
| 82 | + >, |
| 83 | + rules, |
| 84 | +}; |
| 85 | + |
| 86 | +const createRCConfig = (rules: Record<string, TSESLint.Linter.RuleLevel>) => ({ |
72 | 87 | plugins: ['jest-extended'], |
73 | 88 | rules, |
74 | 89 | }); |
75 | 90 |
|
76 | | -export = { |
77 | | - configs: { |
78 | | - all: createConfig(allRules), |
79 | | - recommended: createConfig(recommendedRules), |
80 | | - }, |
| 91 | +const createFlatConfig = ( |
| 92 | + rules: Record<string, TSESLint.Linter.RuleLevel>, |
| 93 | +) => ({ |
| 94 | + plugins: { 'jest-extended': plugin }, |
81 | 95 | rules, |
| 96 | +}); |
| 97 | + |
| 98 | +plugin.configs = { |
| 99 | + all: createRCConfig(allRules), |
| 100 | + recommended: createRCConfig(recommendedRules), |
| 101 | + 'flat/all': createFlatConfig(allRules), |
| 102 | + 'flat/recommended': createFlatConfig(recommendedRules), |
82 | 103 | }; |
| 104 | + |
| 105 | +export = plugin; |
0 commit comments