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 : {
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' ,
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 ,
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' ] ,
3768 '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' ] ,
4071 'no-else-return' : [
4172 error ,
4273 {
4374 allowElseIf : true ,
4475 } ,
4576 ] ,
77+ '@typescript-eslint/require-await' : error ,
4678 '@typescript-eslint/unbound-method' : [
4779 error ,
4880 {
4981 ignoreStatic : true ,
5082 } ,
5183 ] ,
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+ ] ,
5293 'no-restricted-imports' : [
5394 'error' ,
5495 {
5596 paths : TEST_ONLY_IMPORTS . map ( ( name ) => {
5697 return { name, message : `${ name } is only available during testing` } ;
5798 } ) ,
58- patterns : TEST_ONLY_IMPORTS . map ( ( dep ) => `${ dep } /*` ) ,
99+ patterns : TEST_ONLY_IMPORTS . map ( dep => `${ dep } /*` ) ,
59100 } ,
60101 ] ,
61- camelcase : off ,
62- '@typescript-eslint/camelcase' : off ,
63- 'require-await' : off ,
64- '@typescript-eslint/require-await' : off ,
65- '@typescript-eslint/indent' : off ,
66102 '@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 ,
71104 '@typescript-eslint/explicit-function-return-type' : off ,
72- '@typescript-eslint/no-var-requires' : off ,
105+ // '@typescript-eslint/no-var-requires': off,
106+
73107 '@typescript-eslint/no-empty-function' : off ,
74- '@typescript-eslint/no-object-literal-type-assertion' : off ,
108+
75109 '@typescript-eslint/no-floating-promises' : error ,
76110 } ,
77111 overrides : [
78112 {
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+ } ,
81122 } ,
82123 {
83124 // TESTING CONFIGURATION
@@ -90,24 +131,26 @@ module.exports = {
90131 'tests/**/*.ts' ,
91132 '__tests__/**/*.js' ,
92133 '__tests__/**/*.ts' ,
93- 'jest.setup.js' ,
134+ 'jest.*.js' ,
135+ 'jest.*.ts' ,
94136 ] ,
95137
96138 // https://eslint.org/docs/user-guide/configuring#specifying-environments
97139 env : {
98140 jest : true ,
99141 } ,
100142
101- // Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
102- // "extends": ["plugin:jest/recommended"]
143+ extends : [ 'plugin:jest/recommended' ] ,
103144 plugins : [ 'jest' ] ,
104145 rules : {
105146 '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' ) ,
111154 } ,
112155 } ,
113156 ] ,
0 commit comments