1
1
import js from '@eslint/js' ;
2
- import tseslint from 'typescript-eslint' ;
3
2
import eslintConfigPrettier from 'eslint-config-prettier' ;
3
+ import tseslint from 'typescript-eslint' ;
4
4
// When it works again do `npm install --save-dev eslint-plugin-import`
5
5
// import imprt from 'eslint-plugin-import';
6
6
// https://github.com/eslint/eslint/issues/18087
7
7
// https://github.com/import-js/eslint-plugin-import/pull/2829
8
- import globals from 'globals' ;
9
8
import jest from 'eslint-plugin-jest' ;
9
+ import reactHooks from 'eslint-plugin-react-hooks' ;
10
+ import reactRefresh from 'eslint-plugin-react-refresh' ;
11
+ import { readFileSync } from 'fs' ;
12
+ import { globSync } from 'glob' ;
13
+ import globals from 'globals' ;
14
+ import { join } from 'path' ;
15
+ // still experimental -->> import { globSync } from 'fs';
16
+ // sitll experimental -->> import packageJSON from './package.json' with { type: 'json' };
17
+
18
+ const packageJSON = JSON . parse ( readFileSync ( './package.json' ) ) ;
19
+ const packageFolders = globSync ( packageJSON . workspaces ) ;
20
+ const multiRootConfigFileGlobs = [
21
+ '.*.js' ,
22
+ '.*.mjs' ,
23
+ '.*.cjs' ,
24
+ '*.config.mjs' ,
25
+ '*.config.cjs' ,
26
+ '*.config.js' ,
27
+ '*.config.ts' ,
28
+ ] ;
29
+
30
+ const configFiles = [ '.' , ...packageFolders ] . flatMap ( ( p ) =>
31
+ multiRootConfigFileGlobs . flatMap ( ( c ) => join ( p , c ) ) ,
32
+ ) ;
10
33
11
34
const off = 'off' ;
12
35
const warn = 'warn' ;
@@ -35,27 +58,22 @@ const any_rules = (level) => {
35
58
export default [
36
59
{
37
60
ignores : [
38
- 'lib/' ,
39
- 'build/' ,
40
- 'build-*/' ,
41
- 'dist/' ,
61
+ '**/ lib/' ,
62
+ '**/ build/' ,
63
+ '**/ build-*/' ,
64
+ '**/ dist/' ,
42
65
'.vscode/' ,
43
- 'node_modules/' ,
44
- 'coverage/' ,
45
- 'report/' ,
66
+ '**/node_modules/' ,
67
+ '**/mocks' ,
68
+ '**/coverage/' ,
69
+ '**/report/' ,
70
+ '**/__snapshots__' ,
46
71
'!*.js' ,
47
72
'!*.mjs' ,
48
73
'!*.cjs' ,
49
74
'!*.ts' ,
50
75
'!.vscode/*.json' ,
51
- 'package-lock.json' ,
52
- '**/node_modules' ,
53
- '**/dist' ,
54
- '**/build' ,
55
- '**/__snapshots__' ,
56
- '**/mocks' ,
57
- '**/coverage' ,
58
- '**/report' ,
76
+ '**/package-lock.json' ,
59
77
] ,
60
78
} ,
61
79
js . configs . recommended ,
@@ -67,14 +85,9 @@ export default [
67
85
globals : globals . node ,
68
86
parser : tseslint . parser ,
69
87
parserOptions : {
70
- ecmaVersion : 2022 ,
71
88
sourceType : 'module' ,
72
89
tsconfigRootDir : import . meta. dirname ,
73
- project : [
74
- './tsconfig.eslint.json' ,
75
- './tsconfig.json' ,
76
- './tsconfig.node.json' ,
77
- ] ,
90
+ projectService : true ,
78
91
} ,
79
92
} ,
80
93
} ,
@@ -133,15 +146,7 @@ export default [
133
146
} ,
134
147
{
135
148
name : 'linting for configuration files' ,
136
- files : [
137
- '.*.js' ,
138
- '.*.mjs' ,
139
- '.*.cjs' ,
140
- '*.config.mjs' ,
141
- '*.config.cjs' ,
142
- '*.config.js' ,
143
- '*.config.ts' ,
144
- ] ,
149
+ files : configFiles ,
145
150
rules : {
146
151
'no-restricted-imports' : off ,
147
152
// Consider if this is too leanient for tests
@@ -166,9 +171,6 @@ export default [
166
171
// https://eslint.org/docs/user-guide/configuring#specifying-environments
167
172
languageOptions : {
168
173
globals : { ...globals . jest , ...globals . node } ,
169
- parserOptions : {
170
- project : [ './tests/tsconfig.json' ] ,
171
- } ,
172
174
} ,
173
175
plugins : { jest } ,
174
176
rules : {
@@ -183,4 +185,37 @@ export default [
183
185
...any_rules ( 'off' ) ,
184
186
} ,
185
187
} ,
188
+ {
189
+ files : [ join ( 'packages' , 'backend' , '**' , '*.{ts,tsx,mtsx,mts}' ) ] ,
190
+ languageOptions : {
191
+ parserOptions : {
192
+ sourceType : 'module' ,
193
+ tsconfigRootDir : join ( import . meta. dirname , 'packages' , 'backend' ) ,
194
+ projectService : true ,
195
+ } ,
196
+ } ,
197
+ } ,
198
+ {
199
+ files : [ join ( 'packages' , 'frontend' , '**' , '*.{ts,tsx,mtsx,mts}' ) ] ,
200
+ plugins : {
201
+ 'react-hooks' : reactHooks ,
202
+ 'react-refresh' : reactRefresh ,
203
+ } ,
204
+ languageOptions : {
205
+ ecmaVersion : 2022 ,
206
+ globals : globals . browser ,
207
+ parserOptions : {
208
+ sourceType : 'module' ,
209
+ tsconfigRootDir : join ( import . meta. dirname , 'packages' , 'frontend' ) ,
210
+ projectService : true ,
211
+ } ,
212
+ } ,
213
+ rules : {
214
+ ...reactHooks . configs . recommended . rules ,
215
+ 'react-refresh/only-export-components' : [
216
+ 'warn' ,
217
+ { allowConstantExport : true } ,
218
+ ] ,
219
+ } ,
220
+ } ,
186
221
] ;
0 commit comments