11const defaultConfig = {
2- extends : [
3- 'eslint:recommended' ,
4- 'plugin:json/recommended' ,
5- 'plugin:prettier/recommended' ,
6- ] ,
2+ extends : [ 'eslint:recommended' , 'plugin:prettier/recommended' ] ,
73 plugins : [ ] ,
84 parserOptions : {
95 sourceType : 'module' ,
@@ -13,27 +9,74 @@ const defaultConfig = {
139 node : true ,
1410 } ,
1511 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+ ] ,
1633 'prettier/prettier' : 'error' ,
1734 'sort-imports' : 'error' ,
1835 } ,
1936} ;
2037
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+
2164const config = defaultConfig ;
2265config . overrides = [
2366 {
2467 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 (
3169 'plugin:@typescript-eslint/recommended' ,
3270 'prettier/@typescript-eslint' ,
33- 'plugin:prettier/recommended ' ,
34- ] ,
71+ 'plugin:jest/style ' ,
72+ ) ,
3573 parser : '@typescript-eslint/parser' ,
3674 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' ) ,
3780 } ,
3881] ;
3982
0 commit comments