1
1
const defaultConfig = {
2
- extends : [
3
- 'eslint:recommended' ,
4
- 'plugin:json/recommended' ,
5
- 'plugin:prettier/recommended' ,
6
- ] ,
2
+ extends : [ 'eslint:recommended' , 'plugin:prettier/recommended' ] ,
7
3
plugins : [ ] ,
8
4
parserOptions : {
9
5
sourceType : 'module' ,
@@ -13,27 +9,74 @@ const defaultConfig = {
13
9
node : true ,
14
10
} ,
15
11
rules : {
12
+ 'no-restricted-globals' : [
13
+ 'error' ,
14
+ /**
15
+ * From Jest global environment.
16
+ * https://github.com/facebook/jest/blob/v26.4.2/packages/jest-globals/src/index.ts#L12-L27
17
+ */
18
+ 'jest' ,
19
+ 'expect' ,
20
+ 'it' ,
21
+ 'test' ,
22
+ 'fit' ,
23
+ 'xit' ,
24
+ 'xtest' ,
25
+ 'describe' ,
26
+ 'xdescribe' ,
27
+ 'fdescribe' ,
28
+ 'beforeAll' ,
29
+ 'beforeEach' ,
30
+ 'afterEach' ,
31
+ 'afterAll' ,
32
+ ] ,
16
33
'prettier/prettier' : 'error' ,
17
34
'sort-imports' : 'error' ,
18
35
} ,
19
36
} ;
20
37
38
+ /**
39
+ * Add to `extends` of `defaultConfig`.
40
+ *
41
+ * The Prettier recommended configuration must be the last extension. See
42
+ * https://github.com/prettier/eslint-plugin-prettier#recommended-configuration.
43
+ *
44
+ * @param {...configurations } configurations Configuration(s) to add.
45
+ * @return Superset of the `extends` with the given configuration(s) added.
46
+ */
47
+ function addToDefaultExtends ( ...configurations ) {
48
+ const prettierConfiguration = 'plugin:prettier/recommended' ;
49
+ const extendsSuperset = defaultConfig . extends
50
+ . concat ( configurations )
51
+ . sort ( ( a , b ) => {
52
+ if ( b === prettierConfiguration ) {
53
+ return - 1 ;
54
+ }
55
+ if ( a === prettierConfiguration ) {
56
+ return 1 ;
57
+ }
58
+ return 0 ;
59
+ } ) ;
60
+
61
+ return extendsSuperset ;
62
+ }
63
+
21
64
const config = defaultConfig ;
22
65
config . overrides = [
23
66
{
24
67
files : [ '**/*.ts' , '**/*.tsx' ] ,
25
- /**
26
- * The Prettier recommended configuration must remain the configuration that
27
- * is extended last. Therefore, this overrides `extends` completely.
28
- */
29
- extends : [
30
- 'eslint:recommended' ,
68
+ extends : addToDefaultExtends (
31
69
'plugin:@typescript-eslint/recommended' ,
32
70
'prettier/@typescript-eslint' ,
33
- 'plugin:prettier/recommended ' ,
34
- ] ,
71
+ 'plugin:jest/style ' ,
72
+ ) ,
35
73
parser : '@typescript-eslint/parser' ,
36
74
plugins : defaultConfig . plugins . concat ( [ '@typescript-eslint' ] ) ,
75
+ rules : { ...defaultConfig . rules , 'jest/consistent-test-it' : 'error' } ,
76
+ } ,
77
+ {
78
+ files : [ '**/*.json' ] ,
79
+ extends : addToDefaultExtends ( 'plugin:json/recommended' ) ,
37
80
} ,
38
81
] ;
39
82
0 commit comments