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
54
ecmaVersion : 2022 ,
27
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 ,
64
+ ...customized . rules ,
65
+ 'import/no-extraneous-dependencies' : error ,
33
66
'no-console' : error ,
67
+ '@typescript-eslint/return-await' : [ 'error' , 'always' ] ,
34
68
'no-unused-vars' : off ,
35
69
'@typescript-eslint/no-unused-vars' : error ,
36
- eqeqeq : [ error , 'smart' ] ,
70
+ ' eqeqeq' : [ error , 'smart' ] ,
37
71
'no-else-return' : [
38
72
error ,
39
73
{
40
74
allowElseIf : true ,
41
75
} ,
42
76
] ,
77
+ '@typescript-eslint/require-await' : error ,
43
78
'@typescript-eslint/unbound-method' : [
44
79
error ,
45
80
{
46
81
ignoreStatic : true ,
47
82
} ,
48
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
+ ] ,
49
93
'no-restricted-imports' : [
50
94
'error' ,
51
95
{
52
96
paths : TEST_ONLY_IMPORTS . map ( ( name ) => {
53
97
return { name, message : `${ name } is only available during testing` } ;
54
98
} ) ,
55
- patterns : TEST_ONLY_IMPORTS . map ( ( dep ) => `${ dep } /*` ) ,
99
+ patterns : TEST_ONLY_IMPORTS . map ( dep => `${ dep } /*` ) ,
56
100
} ,
57
101
] ,
58
- camelcase : off ,
59
- 'require-await' : off ,
60
- '@typescript-eslint/require-await' : off ,
61
- '@typescript-eslint/indent' : off ,
62
102
'@typescript-eslint/explicit-member-accessibility' : warn ,
63
- '@typescript-eslint/no-explicit-any' : off ,
64
- '@typescript-eslint/no-unsafe-argument' : off ,
65
- '@typescript-eslint/no-unsafe-return' : off ,
66
- '@typescript-eslint/no-unsafe-assignment' : off ,
103
+ '@typescript-eslint/no-explicit-any' : warn ,
67
104
'@typescript-eslint/explicit-function-return-type' : off ,
68
- '@typescript-eslint/no-var-requires' : off ,
105
+ // '@typescript-eslint/no-var-requires': off,
106
+
69
107
'@typescript-eslint/no-empty-function' : off ,
108
+
70
109
'@typescript-eslint/no-floating-promises' : error ,
71
110
} ,
72
111
overrides : [
73
112
{
74
- files : [ '*.ts' , '*.tsx' ] ,
75
- 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
+ } ,
76
122
} ,
77
123
{
78
124
// TESTING CONFIGURATION
@@ -87,16 +133,13 @@ module.exports = {
87
133
'__tests__/**/*.ts' ,
88
134
'jest.*.js' ,
89
135
'jest.*.ts' ,
90
- '.*.ts' ,
91
- '.*.js' ,
92
136
] ,
93
137
94
138
// https://eslint.org/docs/user-guide/configuring#specifying-environments
95
139
env : {
96
140
jest : true ,
97
141
} ,
98
142
99
- // Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
100
143
extends : [ 'plugin:jest/recommended' ] ,
101
144
plugins : [ 'jest' ] ,
102
145
rules : {
@@ -107,6 +150,7 @@ module.exports = {
107
150
assertFunctionNames : [ 'expect' , 'fc.assert' ] ,
108
151
} ,
109
152
] ,
153
+ ...any_rules ( 'off' ) ,
110
154
} ,
111
155
} ,
112
156
] ,
0 commit comments