1+ // @ts -check
2+ const stylistic = require ( '@stylistic/eslint-plugin' ) ;
3+
14const off = 'off' ;
25
36const warn = 'warn' ;
47
58const error = 'error' ;
69
710const 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+ } ;
832
933module . exports = {
1034 extends : [
1135 'eslint:recommended' ,
1236 'plugin:@typescript-eslint/eslint-recommended' ,
1337 'plugin:@typescript-eslint/recommended' ,
1438 'plugin:@typescript-eslint/recommended-requiring-type-checking' ,
15- 'plugin:prettier/recommended' ,
1639 'plugin:import/errors' ,
1740 'plugin:import/warnings' ,
1841 'plugin:import/typescript' ,
42+ // 'plugin:prettier/recommended',
43+ // 'prettier',
1944 ] ,
2045 env : {
2146 node : true ,
2247 } ,
23- plugins : [ '@typescript-eslint/eslint-plugin' ] ,
48+ plugins : [
49+ '@typescript-eslint/eslint-plugin' ,
50+ '@stylistic' , // stylistic rules were migrated here
51+ ] ,
2452 parser : '@typescript-eslint/parser' ,
2553 parserOptions : {
2654 ecmaVersion : 2022 ,
2755 sourceType : 'module' ,
2856 tsconfigRootDir : __dirname ,
29- project : [ './tsconfig.eslint.json' ] ,
57+ project : [
58+ './tsconfig.eslint.json' ,
59+ './tsconfig.json' ,
60+ '/tsconfig.prod.json' ,
61+ ] ,
3062 } ,
3163 rules : {
32- 'import/no-extraneous-dependencies' : warn ,
64+ ...customized . rules ,
65+ 'import/no-extraneous-dependencies' : error ,
3366 'no-console' : error ,
67+ '@typescript-eslint/return-await' : [ 'error' , 'always' ] ,
3468 'no-unused-vars' : off ,
3569 '@typescript-eslint/no-unused-vars' : error ,
36- eqeqeq : [ error , 'smart' ] ,
70+ ' eqeqeq' : [ error , 'smart' ] ,
3771 'no-else-return' : [
3872 error ,
3973 {
4074 allowElseIf : true ,
4175 } ,
4276 ] ,
77+ '@typescript-eslint/require-await' : error ,
4378 '@typescript-eslint/unbound-method' : [
4479 error ,
4580 {
4681 ignoreStatic : true ,
4782 } ,
4883 ] ,
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+ ] ,
4993 'no-restricted-imports' : [
5094 'error' ,
5195 {
5296 paths : TEST_ONLY_IMPORTS . map ( ( name ) => {
5397 return { name, message : `${ name } is only available during testing` } ;
5498 } ) ,
55- patterns : TEST_ONLY_IMPORTS . map ( ( dep ) => `${ dep } /*` ) ,
99+ patterns : TEST_ONLY_IMPORTS . map ( dep => `${ dep } /*` ) ,
56100 } ,
57101 ] ,
58- camelcase : off ,
59- 'require-await' : off ,
60- '@typescript-eslint/require-await' : off ,
61- '@typescript-eslint/indent' : off ,
62102 '@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 ,
67104 '@typescript-eslint/explicit-function-return-type' : off ,
68- '@typescript-eslint/no-var-requires' : off ,
105+ // '@typescript-eslint/no-var-requires': off,
106+
69107 '@typescript-eslint/no-empty-function' : off ,
108+
70109 '@typescript-eslint/no-floating-promises' : error ,
71110 } ,
72111 overrides : [
73112 {
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+ } ,
76122 } ,
77123 {
78124 // TESTING CONFIGURATION
@@ -87,16 +133,13 @@ module.exports = {
87133 '__tests__/**/*.ts' ,
88134 'jest.*.js' ,
89135 'jest.*.ts' ,
90- '.*.ts' ,
91- '.*.js' ,
92136 ] ,
93137
94138 // https://eslint.org/docs/user-guide/configuring#specifying-environments
95139 env : {
96140 jest : true ,
97141 } ,
98142
99- // Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
100143 extends : [ 'plugin:jest/recommended' ] ,
101144 plugins : [ 'jest' ] ,
102145 rules : {
@@ -107,6 +150,7 @@ module.exports = {
107150 assertFunctionNames : [ 'expect' , 'fc.assert' ] ,
108151 } ,
109152 ] ,
153+ ...any_rules ( 'off' ) ,
110154 } ,
111155 } ,
112156 ] ,
0 commit comments