Skip to content

Commit

Permalink
refactor: make config rules static rather than based off rule metadata (
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Mar 21, 2024
1 parent e212f5e commit ff16ef2
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,34 @@ const rules = Object.fromEntries(
.map(rule => [rule, importDefault(join(rulesDir, rule)) as RuleModule]),
);

const recommendedRules = Object.fromEntries(
Object.entries(rules)
.filter(([, rule]) => rule.meta.docs.recommended)
.map(([name, rule]) => [
`jest/${name}`,
rule.meta.docs.recommended as TSESLint.Linter.RuleLevel,
]),
);
const recommendedRules = {
'jest/expect-expect': 'warn',
'jest/no-alias-methods': 'error',
'jest/no-commented-out-tests': 'warn',
'jest/no-conditional-expect': 'error',
'jest/no-deprecated-functions': 'error',
'jest/no-disabled-tests': 'warn',
'jest/no-done-callback': 'error',
'jest/no-export': 'error',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/no-interpolation-in-snapshots': 'error',
'jest/no-jasmine-globals': 'error',
'jest/no-mocks-import': 'error',
'jest/no-standalone-expect': 'error',
'jest/no-test-prefixes': 'error',
'jest/valid-describe-callback': 'error',
'jest/valid-expect': 'error',
'jest/valid-expect-in-promise': 'error',
'jest/valid-title': 'error',
} satisfies Record<string, TSESLint.Linter.RuleLevel>;

const styleRules = {
'jest/no-alias-methods': 'warn',
'jest/prefer-to-be': 'error',
'jest/prefer-to-contain': 'error',
'jest/prefer-to-have-length': 'error',
} satisfies Record<string, TSESLint.Linter.RuleLevel>;

const allRules = Object.fromEntries<TSESLint.Linter.RuleLevel>(
Object.entries(rules)
Expand Down Expand Up @@ -122,20 +142,10 @@ const createFlatConfig = (
plugin.configs = {
all: createRCConfig(allRules),
recommended: createRCConfig(recommendedRules),
style: createRCConfig({
'jest/no-alias-methods': 'warn',
'jest/prefer-to-be': 'error',
'jest/prefer-to-contain': 'error',
'jest/prefer-to-have-length': 'error',
}),
style: createRCConfig(styleRules),
'flat/all': createFlatConfig(allRules),
'flat/recommended': createFlatConfig(recommendedRules),
'flat/style': createFlatConfig({
'jest/no-alias-methods': 'warn',
'jest/prefer-to-be': 'error',
'jest/prefer-to-contain': 'error',
'jest/prefer-to-have-length': 'error',
}),
'flat/style': createFlatConfig(styleRules),
'flat/snapshots': {
// @ts-expect-error this is introduced in flat config
files: ['**/*.snap'],
Expand Down

0 comments on commit ff16ef2

Please # to comment.