-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patheslint.config.js
More file actions
373 lines (341 loc) · 12.2 KB
/
eslint.config.js
File metadata and controls
373 lines (341 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
import js from "@eslint/js";
import typescript from "@typescript-eslint/eslint-plugin";
import typescriptParser from "@typescript-eslint/parser";
import importPlugin from "eslint-plugin-import";
import nodePlugin from "eslint-plugin-node";
import promisePlugin from "eslint-plugin-promise";
import globals from "globals";
export default [
// Ignore build artifacts and subproject node_modules/ui to reduce noise
{
ignores: [
"dist/**",
"dist-test/**",
"node_modules/**",
"test-all-features.*", // Not in tsconfig.json project
"examples/**",
"reports/**", // Generated code quality reports
],
},
// JavaScript files configuration
{
files: ["**/*.{js,mjs,cjs}"],
ignores: ["eslint.config.js"], // Exclude ESLint config from import resolution checks
plugins: {
js,
import: importPlugin,
node: nodePlugin,
promise: promisePlugin,
},
languageOptions: {
globals: globals.node,
ecmaVersion: 2022,
sourceType: "module",
},
rules: {
...js.configs.recommended.rules,
// Strict variable rules
"no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"no-var": "error",
"prefer-const": "error",
"no-redeclare": "error",
// Error handling - allow console in main server file
"no-console": "warn",
"no-debugger": "error",
"no-alert": "error",
// Best practices
"eqeqeq": ["error", "always"],
"curly": ["error", "all"],
"no-eval": "error",
"no-implied-eval": "error",
"no-new-func": "error",
"no-return-assign": "error",
"no-sequences": "error",
"no-throw-literal": "error",
"no-unmodified-loop-condition": "error",
"no-unused-expressions": "error",
"no-useless-call": "error",
"no-useless-concat": "error",
"no-useless-return": "error",
"prefer-promise-reject-errors": "error",
"require-await": "error",
// Import rules
"import/no-unresolved": "error",
"import/named": "error",
"import/default": "error",
"import/no-absolute-path": "error",
"import/no-self-import": "error",
"import/no-cycle": "error",
"import/no-useless-path-segments": "error",
"import/no-deprecated": "warn",
// Node.js rules
"node/no-missing-import": "off", // Handled by TypeScript
"node/no-unsupported-features/es-syntax": "off", // We use ES modules
// Promise rules
"promise/always-return": "error",
"promise/catch-or-return": "error",
"promise/param-names": "error",
"promise/no-return-wrap": "error",
},
},
// TypeScript files configuration - ULTRA STRICT
{
files: ["**/*.{ts,tsx}"],
plugins: {
"@typescript-eslint": typescript,
import: importPlugin,
node: nodePlugin,
promise: promisePlugin,
},
languageOptions: {
parser: typescriptParser,
parserOptions: {
ecmaVersion: 2022,
sourceType: "module",
project: [
"./tsconfig.json",
],
tsconfigRootDir: process.cwd(),
},
globals: globals.node,
},
rules: {
// Base ESLint rules (disabled in favor of TypeScript versions)
"no-unused-vars": "off",
"no-redeclare": "off",
"no-shadow": "off",
"no-use-before-define": "off",
"no-useless-constructor": "off",
"no-empty-function": "off",
"no-array-constructor": "off",
"no-loss-of-precision": "off",
"no-loop-func": "off",
"no-magic-numbers": "off",
// TypeScript-specific STRICT rules
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
},
],
"@typescript-eslint/no-explicit-any": "warn",
// Type checking - relax some strictness to prioritize high-impact fixes
"@typescript-eslint/strict-boolean-expressions": "off", // Too strict for practical use
"@typescript-eslint/no-unnecessary-condition": "off", // Can conflict with defensive programming
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "off", // Can be overly strict
"@typescript-eslint/no-unnecessary-type-constraint": "error",
// Function rules
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/no-misused-promises": ["error", {
checksConditionals: true,
checksVoidReturn: true,
}],
"@typescript-eslint/require-await": "off", // Too strict for utility functions
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/promise-function-async": "off", // Too opinionated
// Variable and naming
"@typescript-eslint/no-redeclare": "error",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/prefer-readonly": "off", // Can be overly strict
"@typescript-eslint/prefer-readonly-parameter-types": "off", // Too strict for Express
// Array and object rules
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/prefer-reduce-type-parameter": "error",
// Class rules
"@typescript-eslint/no-useless-empty-export": "error",
"@typescript-eslint/no-extraneous-class": "error",
// Import and module rules
"@typescript-eslint/consistent-type-imports": ["error", {
prefer: "type-imports",
disallowTypeAnnotations: false,
}],
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/no-import-type-side-effects": "error",
// Formatting and style - removed as these rules are deprecated
// Error handling
"no-console": "off", // Allow console in all files
"no-debugger": "error",
"no-alert": "error",
// Best practices
"eqeqeq": ["error", "always"],
"curly": ["error", "all"],
"no-eval": "error",
"no-implied-eval": "error",
"no-new-func": "error",
"no-return-assign": "error",
"no-sequences": "error",
"no-throw-literal": "error",
"no-unmodified-loop-condition": "error",
"no-unused-expressions": "error",
"no-useless-call": "error",
"no-useless-concat": "error",
"no-useless-return": "error",
"prefer-promise-reject-errors": "error",
// SSOT/DRY/KISS Enforcement Rules
// File size limits (KISS principle - max 300 lines)
"max-lines": ["error", {
max: 300,
skipBlankLines: true,
skipComments: true
}],
// Function size limits (KISS principle - max 50 lines)
"max-lines-per-function": ["error", {
max: 50,
skipBlankLines: true,
skipComments: true,
IIFEs: true
}],
// Complexity limits (KISS principle - max cyclomatic complexity 10)
"complexity": ["error", { max: 10 }],
// Nesting depth limits (KISS principle - max 3 levels)
"max-depth": ["error", { max: 3 }],
// Parameter count limits (KISS principle - max 4 parameters)
"max-params": ["error", { max: 4 }],
// Statement limits per function (KISS principle - max 30 statements)
"max-statements": ["error", { max: 30 }, { ignoreTopLevelFunctions: false }],
// Duplicate code prevention (DRY principle)
"no-duplicate-imports": "error",
// Import rules for TypeScript
"import/no-unresolved": "off", // TypeScript handles module resolution
"import/named": "off", // TypeScript handles this
"import/default": "off", // TypeScript handles this
"import/no-absolute-path": "error",
"import/no-self-import": "error",
"import/no-cycle": "error",
"import/no-useless-path-segments": "error",
"import/no-deprecated": "warn",
"import/order": ["error", {
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
"type"
],
"newlines-between": "always",
alphabetize: { order: "asc", caseInsensitive: true },
}],
// Promise rules
"promise/always-return": "error",
"promise/catch-or-return": "error",
"promise/param-names": "error",
"promise/no-return-wrap": "error",
},
},
// Test files - slightly relaxed rules
{
files: ["**/*.test.{ts,js}", "**/test/**/*.{ts,js}", "**/tests/**/*.{ts,js}"],
plugins: {
"@typescript-eslint": typescript,
import: importPlugin,
node: nodePlugin,
promise: promisePlugin,
},
languageOptions: {
parser: typescriptParser,
parserOptions: {
ecmaVersion: 2022,
sourceType: "module",
project: "./tsconfig.json",
tsconfigRootDir: process.cwd(),
},
globals: globals.node,
},
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-expressions": "off", // Chai expressions
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/no-unnecessary-condition": "off",
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/no-floating-promises": "off",
"promise/always-return": "off",
"promise/param-names": "off",
"curly": "off",
"no-console": "off",
// Base ESLint rule must also be disabled for test files so Chai-style
// assertions like `expect(...).to.be.true` don't trigger errors.
"no-unused-expressions": "off",
// Relax import order constraints for tests to reduce noise
"import/order": "off",
// Test files can be longer
"max-lines": ["error", { max: 500, skipBlankLines: true, skipComments: true }],
"max-lines-per-function": ["error", { max: 100, skipBlankLines: true, skipComments: true }],
"max-statements": ["error", { max: 50 }],
},
},
// Legacy files being refactored - warnings only (temporary)
// Per AGENTS.md: These files have "accepted appropriate complexity" due to inherent
// complexity of bidirectional streaming translation with tool calling
{
files: [
// XML Parsers
"src/parsers/xml/**/*.ts",
// Stream Processors (bidirectional streaming - inherently complex)
"src/handlers/stream/**/*.ts",
"src/handlers/streamingHandler.ts",
// Translation Converters (format conversion - inherently complex)
"src/translation/**/*.ts",
// Services
"src/services/**/*.ts",
// Handlers (API endpoint handlers)
"src/handlers/chatHandler.ts",
"src/handlers/ollamaGenerateHandler.ts",
"src/handlers/ollamaShowHandler.ts",
// Config (central configuration - data file)
"src/config.ts",
// Main entry point
"src/index.ts",
// HTTP utilities
"src/utils/http/*.ts",
],
rules: {
"max-lines": "warn",
"max-lines-per-function": "warn",
"complexity": "warn",
"max-depth": "warn",
"max-statements": "warn",
"max-params": "warn",
},
},
// Test utilities - allow more complexity for test infrastructure
{
files: [
"src/test/utils/*.ts",
"src/test/runners/*.ts",
"scripts/manual/*.ts",
],
rules: {
"max-lines": "warn",
"max-lines-per-function": "warn",
"complexity": "warn",
"max-depth": "warn",
"max-statements": "warn",
"max-params": "warn",
"@typescript-eslint/no-explicit-any": "off",
},
},
];