1
+ // @ts -check
2
+ const stylistic = require ( '@stylistic/eslint-plugin' ) ;
3
+
1
4
const off = 'off' ;
2
5
3
6
const warn = 'warn' ;
4
7
5
8
const error = 'error' ;
6
9
7
10
const TEST_ONLY_IMPORTS = [ 'fast-check' , 'jest' , 'eslint' , 'prettier' ] ;
11
+ const customized = stylistic . configs . customize ( {
12
+ // the following options are the default values
13
+ semi : true ,
14
+ blockSpacing : true ,
15
+ } ) ;
16
+
17
+ /**
18
+ * set of typescript-eslint any rules
19
+ * @param {string } level
20
+ * @returns
21
+ */
22
+ const any_rules = ( level ) => {
23
+ return {
24
+ '@typescript-eslint/no-unsafe-return' : level ,
25
+ '@typescript-eslint/no-var-requires' : level ,
26
+ '@typescript-eslint/no-unsafe-member-access' : level ,
27
+ '@typescript-eslint/no-unsafe-argument' : level ,
28
+ '@typescript-eslint/no-unsafe-call' : level ,
29
+ '@typescript-eslint/no-explicit-any' : level ,
30
+ } ;
31
+ } ;
8
32
9
33
module . exports = {
10
34
extends : [
11
35
'eslint:recommended' ,
12
36
'plugin:@typescript-eslint/eslint-recommended' ,
13
37
'plugin:@typescript-eslint/recommended' ,
14
38
'plugin:@typescript-eslint/recommended-requiring-type-checking' ,
15
- 'plugin:prettier/recommended' ,
16
39
'plugin:import/errors' ,
17
40
'plugin:import/warnings' ,
18
41
'plugin:import/typescript' ,
42
+ // 'plugin:prettier/recommended',
43
+ // 'prettier',
19
44
] ,
20
45
env : {
21
46
node : true ,
22
47
} ,
23
- plugins : [ '@typescript-eslint/eslint-plugin' ] ,
48
+ plugins : [
49
+ '@typescript-eslint/eslint-plugin' ,
50
+ '@stylistic' , // stylistic rules were migrated here
51
+ ] ,
24
52
parser : '@typescript-eslint/parser' ,
25
53
parserOptions : {
26
- ecmaVersion : 2020 , // Allows for the parsing of modern ECMAScript features
27
- sourceType : 'module' , // Allows for the use of imports
54
+ ecmaVersion : 2022 ,
55
+ sourceType : 'module' ,
28
56
tsconfigRootDir : __dirname ,
29
- project : [ './tsconfig.eslint.json' ] ,
57
+ project : [
58
+ './tsconfig.eslint.json' ,
59
+ './tsconfig.json' ,
60
+ '/tsconfig.prod.json' ,
61
+ ] ,
30
62
} ,
31
63
rules : {
32
- 'import/no-extraneous-dependencies' : warn ,
33
-
34
- // Temporal?
35
- 'no-console' : warn ,
36
- 'no-return-await' : warn ,
64
+ ...customized . rules ,
65
+ 'import/no-extraneous-dependencies' : error ,
66
+ 'no-console' : error ,
67
+ '@typescript-eslint/return-await' : [ 'error' , 'always' ] ,
37
68
'no-unused-vars' : off ,
38
- '@typescript-eslint/no-unused-vars' : off ,
39
- eqeqeq : [ error , 'smart' ] ,
69
+ '@typescript-eslint/no-unused-vars' : error ,
70
+ ' eqeqeq' : [ error , 'smart' ] ,
40
71
'no-else-return' : [
41
72
error ,
42
73
{
43
74
allowElseIf : true ,
44
75
} ,
45
76
] ,
77
+ '@typescript-eslint/require-await' : error ,
46
78
'@typescript-eslint/unbound-method' : [
47
79
error ,
48
80
{
49
81
ignoreStatic : true ,
50
82
} ,
51
83
] ,
84
+ // See https://github.com/orgs/react-hook-form/discussions/8622#discussioncomment-4060570
85
+ '@typescript-eslint/no-misused-promises' : [
86
+ error ,
87
+ {
88
+ checksVoidReturn : {
89
+ attributes : false ,
90
+ } ,
91
+ } ,
92
+ ] ,
52
93
'no-restricted-imports' : [
53
94
'error' ,
54
95
{
55
96
paths : TEST_ONLY_IMPORTS . map ( ( name ) => {
56
97
return { name, message : `${ name } is only available during testing` } ;
57
98
} ) ,
58
- patterns : TEST_ONLY_IMPORTS . map ( ( dep ) => `${ dep } /*` ) ,
99
+ patterns : TEST_ONLY_IMPORTS . map ( dep => `${ dep } /*` ) ,
59
100
} ,
60
101
] ,
61
- camelcase : off ,
62
- '@typescript-eslint/camelcase' : off ,
63
- 'require-await' : off ,
64
- '@typescript-eslint/require-await' : off ,
65
- '@typescript-eslint/indent' : off ,
66
102
'@typescript-eslint/explicit-member-accessibility' : warn ,
67
- '@typescript-eslint/no-explicit-any' : off ,
68
- '@typescript-eslint/no-unsafe-argument' : off ,
69
- '@typescript-eslint/no-unsafe-return' : off ,
70
- '@typescript-eslint/no-unsafe-assignment' : off ,
103
+ '@typescript-eslint/no-explicit-any' : warn ,
71
104
'@typescript-eslint/explicit-function-return-type' : off ,
72
- '@typescript-eslint/no-var-requires' : off ,
105
+ // '@typescript-eslint/no-var-requires': off,
106
+
73
107
'@typescript-eslint/no-empty-function' : off ,
74
- '@typescript-eslint/no-object-literal-type-assertion' : off ,
108
+
75
109
'@typescript-eslint/no-floating-promises' : error ,
76
110
} ,
77
111
overrides : [
78
112
{
79
- files : [ '*.ts' , '*.tsx' ] ,
80
- rules : { } ,
113
+ files : [ '.*.js' , '.*.cjs' , '*.config.cjs' , '*.config.js' , '*.config.ts' ] ,
114
+ env : {
115
+ node : true ,
116
+ } ,
117
+ rules : {
118
+ 'no-restricted-imports' : off ,
119
+ // Consider if this is too leanient for tests
120
+ ...any_rules ( 'off' ) ,
121
+ } ,
81
122
} ,
82
123
{
83
124
// TESTING CONFIGURATION
@@ -90,24 +131,26 @@ module.exports = {
90
131
'tests/**/*.ts' ,
91
132
'__tests__/**/*.js' ,
92
133
'__tests__/**/*.ts' ,
93
- 'jest.setup.js' ,
134
+ 'jest.*.js' ,
135
+ 'jest.*.ts' ,
94
136
] ,
95
137
96
138
// https://eslint.org/docs/user-guide/configuring#specifying-environments
97
139
env : {
98
140
jest : true ,
99
141
} ,
100
142
101
- // Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
102
- // "extends": ["plugin:jest/recommended"]
143
+ extends : [ 'plugin:jest/recommended' ] ,
103
144
plugins : [ 'jest' ] ,
104
145
rules : {
105
146
'no-restricted-imports' : off ,
106
- 'jest/no-disabled-tests' : warn ,
107
- 'jest/no-focused-tests' : error ,
108
- 'jest/no-identical-title' : error ,
109
- 'jest/prefer-to-have-length' : warn ,
110
- 'jest/valid-expect' : error ,
147
+ 'jest/expect-expect' : [
148
+ error ,
149
+ {
150
+ assertFunctionNames : [ 'expect' , 'fc.assert' ] ,
151
+ } ,
152
+ ] ,
153
+ ...any_rules ( 'off' ) ,
111
154
} ,
112
155
} ,
113
156
] ,
0 commit comments