1
- // export default {
2
- // parser: '@typescript-eslint/parser',
3
- // plugins: ['@typescript-eslint', 'unused-imports', 'prettier'],
4
- // rules: {
5
- // 'no-unused-vars': 'off',
6
- // 'prettier/prettier': 'error',
7
- // 'unused-imports/no-unused-imports': 'error',
8
- // },
9
- // root: true,
10
- // };
11
-
12
1
import eslint from '@eslint/js' ;
13
- // import someOtherConfig from 'eslint-config-other-configuration-that-enables-formatting-rules';
14
2
import prettierConfig from 'eslint-config-prettier' ;
15
3
import tseslint from 'typescript-eslint' ;
16
4
import { globalIgnores } from 'eslint/config' ;
17
5
18
6
export default tseslint . config (
7
+ // Ignore build outputs and large example folders
19
8
globalIgnores ( [
20
9
'**/dist/**' ,
21
10
'**/dist-cjs/**' ,
@@ -24,30 +13,201 @@ export default tseslint.config(
24
13
'examples/realtime-next/**' ,
25
14
'examples/realtime-demo/**' ,
26
15
'examples/nextjs/**' ,
27
- 'integration-tests//**' ,
16
+ 'examples/tools/**' ,
17
+ 'integration-tests/**' ,
18
+ // Docs code snippets: not intended to pass lint as runtime code
19
+ 'examples/docs/**' ,
20
+ 'packages/**/test/**/*.cjs' ,
21
+ 'packages/**/test/**/*.cjs.map' ,
28
22
] ) ,
23
+
24
+ // Base + TS + Prettier
29
25
eslint . configs . recommended ,
30
26
tseslint . configs . recommended ,
31
27
prettierConfig ,
32
- [
33
- {
34
- rules : {
35
- '@typescript-eslint/no-explicit-any' : 'off' ,
36
- '@typescript-eslint/no-unused-vars' : [
37
- 'error' ,
38
- {
39
- argsIgnorePattern : '^_' ,
40
- varsIgnorePattern : '^_' ,
41
- caughtErrorsIgnorePattern : '^_' ,
42
- } ,
43
- ] ,
28
+
29
+ // Repo-wide TS rules
30
+ {
31
+ rules : {
32
+ '@typescript-eslint/no-explicit-any' : 'off' ,
33
+ '@typescript-eslint/no-unused-vars' : [
34
+ 'error' ,
35
+ {
36
+ argsIgnorePattern : '^_' ,
37
+ varsIgnorePattern : '^_' ,
38
+ caughtErrorsIgnorePattern : '^_' ,
39
+ } ,
40
+ ] ,
41
+ } ,
42
+ } ,
43
+
44
+ // Allow CommonJS in .cjs files (configs, tests, scripts, CJS entrypoints)
45
+ {
46
+ files : [ '**/*.cjs' ] ,
47
+ languageOptions : {
48
+ sourceType : 'script' , // treat as CommonJS
49
+ ecmaVersion : 'latest' ,
50
+ globals : {
51
+ // Node/CJS
52
+ require : 'readonly' ,
53
+ module : 'readonly' ,
54
+ exports : 'readonly' ,
55
+ __dirname : 'readonly' ,
56
+ __filename : 'readonly' ,
57
+ process : 'readonly' ,
58
+ console : 'readonly' ,
59
+ Buffer : 'readonly' ,
60
+ setTimeout : 'readonly' ,
61
+ clearTimeout : 'readonly' ,
62
+ setImmediate : 'readonly' ,
63
+ structuredClone : 'readonly' ,
64
+ URL : 'readonly' ,
65
+ AbortController : 'readonly' ,
66
+ // Some runtimes/polyfills supply these even in CJS contexts
67
+ Response : 'readonly' ,
44
68
} ,
45
69
} ,
46
- {
47
- files : [ 'examples/docs/**' ] ,
48
- rules : {
49
- '@typescript-eslint/no-unused-vars' : 'off' ,
70
+ rules : {
71
+ '@typescript-eslint/no-require-imports' : 'off' ,
72
+ // Helpful if these plugins are present:
73
+ 'import/no-commonjs' : 'off' ,
74
+ 'n/no-missing-require' : 'off' ,
75
+ 'n/no-unsupported-features/es-syntax' : 'off' ,
76
+ 'unicorn/prefer-module' : 'off' ,
77
+ // Some CJS files intentionally use expression statements
78
+ '@typescript-eslint/no-unused-expressions' : 'off' ,
79
+ } ,
80
+ } ,
81
+
82
+ // Tests override: Node + web-like globals used/mocked in CJS tests
83
+ {
84
+ files : [ '**/test/**/*.cjs' ] ,
85
+ languageOptions : {
86
+ sourceType : 'script' ,
87
+ ecmaVersion : 'latest' ,
88
+ globals : {
89
+ // Node-ish
90
+ global : 'readonly' ,
91
+ process : 'readonly' ,
92
+ require : 'readonly' ,
93
+ module : 'readonly' ,
94
+ exports : 'readonly' ,
95
+ console : 'readonly' ,
96
+ setTimeout : 'readonly' ,
97
+ clearTimeout : 'readonly' ,
98
+ setImmediate : 'readonly' ,
99
+ Buffer : 'readonly' ,
100
+ URL : 'readonly' ,
101
+ AbortController : 'readonly' ,
102
+
103
+ // Web APIs commonly mocked/polyfilled in tests
104
+ Event : 'readonly' ,
105
+ EventTarget : 'readonly' ,
106
+ MessageEvent : 'readonly' ,
107
+ TextEncoder : 'readonly' ,
108
+ FormData : 'readonly' ,
109
+ fetch : 'readonly' ,
110
+ navigator : 'readonly' ,
111
+ document : 'readonly' ,
112
+ window : 'readonly' ,
113
+ atob : 'readonly' ,
114
+ btoa : 'readonly' ,
115
+ Response : 'readonly' ,
116
+ RTCPeerConnection : 'readonly' ,
117
+
118
+ // Vitest-style test globals
119
+ describe : 'readonly' ,
120
+ it : 'readonly' ,
121
+ test : 'readonly' ,
122
+ expect : 'readonly' ,
123
+ beforeAll : 'readonly' ,
124
+ afterAll : 'readonly' ,
125
+ beforeEach : 'readonly' ,
126
+ afterEach : 'readonly' ,
127
+ vi : 'readonly' ,
50
128
} ,
51
129
} ,
52
- ] ,
130
+ rules : {
131
+ '@typescript-eslint/no-require-imports' : 'off' ,
132
+ } ,
133
+ } ,
134
+
135
+ // Source CJS that target browser-like environments (e.g., realtime WebRTC)
136
+ {
137
+ files : [ '**/src/**/*.cjs' ] ,
138
+ languageOptions : {
139
+ sourceType : 'script' ,
140
+ ecmaVersion : 'latest' ,
141
+ globals : {
142
+ // Node
143
+ require : 'readonly' ,
144
+ module : 'readonly' ,
145
+ exports : 'readonly' ,
146
+ process : 'readonly' ,
147
+ console : 'readonly' ,
148
+ setTimeout : 'readonly' ,
149
+ clearTimeout : 'readonly' ,
150
+ setImmediate : 'readonly' ,
151
+ Buffer : 'readonly' ,
152
+ structuredClone : 'readonly' ,
153
+ URL : 'readonly' ,
154
+ AbortController : 'readonly' ,
155
+ // Web
156
+ Event : 'readonly' ,
157
+ EventTarget : 'readonly' ,
158
+ MessageEvent : 'readonly' ,
159
+ TextEncoder : 'readonly' ,
160
+ FormData : 'readonly' ,
161
+ fetch : 'readonly' ,
162
+ navigator : 'readonly' ,
163
+ document : 'readonly' ,
164
+ window : 'readonly' ,
165
+ atob : 'readonly' ,
166
+ btoa : 'readonly' ,
167
+ RTCPeerConnection : 'readonly' ,
168
+ CustomEvent : 'readonly' ,
169
+ crypto : 'readonly' ,
170
+ Response : 'readonly' ,
171
+ } ,
172
+ } ,
173
+ } ,
174
+
175
+ // Shims often intentionally shadow/process globals; relax specific rules there
176
+ {
177
+ files : [
178
+ '**/src/shims/**/*.cjs' ,
179
+ '**/src/shims/**/*.js' ,
180
+ '**/src/shims/**/*.ts' ,
181
+ 'docs/src/scripts/**/*.cjs' , // docs script: allow redefining __filename/__dirname
182
+ ] ,
183
+ rules : {
184
+ 'no-redeclare' : 'off' ,
185
+ } ,
186
+ } ,
187
+
188
+ // Lambda test folder uses CommonJS
189
+ {
190
+ files : [ 'lambda-test/**' ] ,
191
+ languageOptions : {
192
+ sourceType : 'script' ,
193
+ globals : {
194
+ require : 'readonly' ,
195
+ module : 'readonly' ,
196
+ exports : 'readonly' ,
197
+ process : 'readonly' ,
198
+ } ,
199
+ } ,
200
+ rules : {
201
+ '@typescript-eslint/no-require-imports' : 'off' ,
202
+ } ,
203
+ } ,
204
+
205
+ // Declaration files: don't flag private class members as unused in .d.ts
206
+ {
207
+ files : [ '**/*.d.ts' ] ,
208
+ rules : {
209
+ 'no-unused-private-class-members' : 'off' ,
210
+ '@typescript-eslint/no-unused-vars' : 'off' ,
211
+ } ,
212
+ } ,
53
213
) ;
0 commit comments