1
1
import { readdirSync } from 'fs' ;
2
2
import { join , parse } from 'path' ;
3
+ import { TSESLint } from '@typescript-eslint/experimental-utils' ;
3
4
import globals from './globals.json' ;
4
5
import * as snapshotProcessor from './processors/snapshot-processor' ;
5
6
7
+ type RuleModule = TSESLint . RuleModule < string , unknown [ ] > & {
8
+ meta : Required < Pick < TSESLint . RuleMetaData < string > , 'docs' > > ;
9
+ } ;
10
+
6
11
// can be removed once we've on v3: https://github.com/typescript-eslint/typescript-eslint/issues/2060
7
12
declare module '@typescript-eslint/experimental-utils/dist/ts-eslint/Rule' {
8
13
export interface RuleMetaDataDocs {
@@ -25,50 +30,38 @@ const excludedFiles = ['__tests__', 'utils'];
25
30
const rules = readdirSync ( rulesDir )
26
31
. map ( rule => parse ( rule ) . name )
27
32
. filter ( rule => ! excludedFiles . includes ( rule ) )
33
+ . reduce < Record < string , RuleModule > > (
34
+ ( acc , curr ) => ( {
35
+ ...acc ,
36
+ [ curr ] : importDefault ( join ( rulesDir , curr ) ) as RuleModule ,
37
+ } ) ,
38
+ { } ,
39
+ ) ;
40
+
41
+ const recommendedRules = Object . entries ( rules )
42
+ . filter ( ( [ , rule ] ) => rule . meta . docs . recommended )
28
43
. reduce (
29
- ( acc , curr ) =>
30
- Object . assign ( acc , { [ curr ] : importDefault ( join ( rulesDir , curr ) ) } ) ,
44
+ ( acc , [ name , rule ] ) => ( {
45
+ ...acc ,
46
+ [ `jest/${ name } ` ] : rule . meta . docs . recommended ,
47
+ } ) ,
31
48
{ } ,
32
49
) ;
33
50
34
- const allRules = Object . keys ( rules ) . reduce < Record < string , string > > (
35
- ( rules , key ) => ( { ...rules , [ `jest/${ key } ` ] : 'error' } ) ,
36
- { } ,
37
- ) ;
51
+ const allRules = Object . keys ( rules ) . reduce <
52
+ Record < string , TSESLint . Linter . RuleLevel >
53
+ > ( ( rules , key ) => ( { ...rules , [ `jest/${ key } ` ] : 'error' } ) , { } ) ;
54
+
55
+ const createConfig = ( rules : Record < string , TSESLint . Linter . RuleLevel > ) => ( {
56
+ plugins : [ 'jest' ] ,
57
+ env : { 'jest/globals' : true } ,
58
+ rules,
59
+ } ) ;
38
60
39
61
export = {
40
62
configs : {
41
- all : {
42
- plugins : [ 'jest' ] ,
43
- env : {
44
- 'jest/globals' : true ,
45
- } ,
46
- rules : allRules ,
47
- } ,
48
- recommended : {
49
- plugins : [ 'jest' ] ,
50
- env : {
51
- 'jest/globals' : true ,
52
- } ,
53
- rules : {
54
- 'jest/expect-expect' : 'warn' ,
55
- 'jest/no-commented-out-tests' : 'warn' ,
56
- 'jest/no-disabled-tests' : 'warn' ,
57
- 'jest/no-export' : 'error' ,
58
- 'jest/no-focused-tests' : 'error' ,
59
- 'jest/no-identical-title' : 'error' ,
60
- 'jest/no-jest-import' : 'error' ,
61
- 'jest/no-mocks-import' : 'error' ,
62
- 'jest/no-jasmine-globals' : 'warn' ,
63
- 'jest/no-standalone-expect' : 'error' ,
64
- 'jest/no-test-callback' : 'error' ,
65
- 'jest/no-test-prefixes' : 'error' ,
66
- 'jest/no-try-expect' : 'error' ,
67
- 'jest/valid-describe' : 'error' ,
68
- 'jest/valid-expect' : 'error' ,
69
- 'jest/valid-expect-in-promise' : 'error' ,
70
- } ,
71
- } ,
63
+ all : createConfig ( allRules ) ,
64
+ recommended : createConfig ( recommendedRules ) ,
72
65
style : {
73
66
plugins : [ 'jest' ] ,
74
67
rules : {
0 commit comments