-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheslint.config.js
More file actions
395 lines (369 loc) · 13.8 KB
/
Copy patheslint.config.js
File metadata and controls
395 lines (369 loc) · 13.8 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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
// @ts-check
import eslint from '@eslint/js';
import barrelFiles from 'eslint-plugin-barrel-files';
import eslintComments from 'eslint-plugin-eslint-comments';
import importPlugin from 'eslint-plugin-import';
import promisePlugin from 'eslint-plugin-promise';
import regexp from 'eslint-plugin-regexp';
import security from 'eslint-plugin-security';
import sonarjs from 'eslint-plugin-sonarjs';
import svelte from 'eslint-plugin-svelte';
import unicorn from 'eslint-plugin-unicorn';
import unusedImports from 'eslint-plugin-unused-imports';
import prettierConfig from 'eslint-config-prettier';
import svelteParser from 'svelte-eslint-parser';
import tseslint from 'typescript-eslint';
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
importPlugin.flatConfigs.recommended,
importPlugin.flatConfigs.typescript,
// @ts-expect-error - flat config exists but types are incomplete
promisePlugin.configs['flat/recommended'],
unicorn.configs.recommended,
sonarjs.configs.recommended,
prettierConfig, // Must be last to disable conflicting formatting rules
{
plugins: {
'barrel-files': barrelFiles,
regexp,
security,
'eslint-comments': eslintComments,
'unused-imports': unusedImports,
},
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
'import/resolver': {
node: true,
typescript: true,
},
},
rules: {
// ===== TypeScript Strict Rules =====
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-unsafe-assignment': 'error',
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'@typescript-eslint/no-unsafe-argument': 'error',
// Allow ONLY `as const`; ban all other assertions (`as Type`, `<Type>expr`)
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'no-restricted-syntax': [
'error',
{
selector: 'TSAsExpression',
message:
'Type assertions (as Type) are disallowed. Use type guards/predicates instead. ' +
'Exception: `as const` is allowed for literal narrowing.',
},
{
selector: 'TSTypeAssertion',
message:
'Angle-bracket type assertions (<Type>expr) are disallowed. Use type guards/predicates instead.',
},
{
selector: 'ExportAllDeclaration',
message:
'Re-exporting with export * is disallowed. ' +
'Import the symbols and export them explicitly at their definition instead.',
},
{
selector: 'ExportNamedDeclaration[source]',
message:
'Re-exporting with export { } from is disallowed. ' +
'Import the symbols and export them explicitly at their definition instead.',
},
{
// bans `arr.map(f => f.prop)` - prefer destructuring `arr.map(({ prop }) => prop)`
selector:
'ArrowFunctionExpression[params.length=1][params.0.type=Identifier][body.type=MemberExpression][body.computed=false]',
message: 'Use destructuring in callback: prefer ({ prop }) => prop over f => f.prop',
},
{
// bans `!!x` - prefer `Boolean(x)` for clarity
selector:
"UnaryExpression[operator='!'][argument.type='UnaryExpression'][argument.operator='!']",
message: 'Use Boolean(x) instead of !!x for explicit type coercion.',
},
],
// Let TypeScript infer return types
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
// Forbid unnecessary type annotations
'@typescript-eslint/no-inferrable-types': [
'error',
{
ignoreParameters: false,
ignoreProperties: false,
},
],
// Forbid .ts extensions in type-only imports side effects
'@typescript-eslint/no-import-type-side-effects': 'error',
// ===== Promise Handling =====
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/return-await': ['error', 'in-try-catch'],
// ===== TypeScript Import/Export =====
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/no-require-imports': 'error',
'no-restricted-imports': [
'error',
{
patterns: [
{
regex: '.*',
importNamePattern: '^\\*$',
message:
'Namespace imports (import * as) are not allowed. Use named imports instead.',
},
{
regex: '\\.js$',
message: 'Do not use .js extension in imports. TypeScript handles module resolution.',
},
],
},
],
// Variable scoping
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
// ===== Import Organization =====
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
'newlines-between': 'never',
alphabetize: { order: 'asc', caseInsensitive: true },
},
],
'sort-imports': ['error', { ignoreDeclarationSort: true }],
// ===== Import Hygiene =====
'import/namespace': 'off', // Slow, TypeScript already validates imports
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
// ===== Unused Imports =====
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'error',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
// ===== Security =====
'@typescript-eslint/no-implied-eval': 'error',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowNumber: true,
allowBoolean: true,
allowAny: false,
allowNullish: false,
},
],
'no-eval': 'error',
'no-new-func': 'error',
'no-script-url': 'error',
'no-inner-declarations': 'error',
// Regex DoS Prevention (eslint-plugin-regexp)
'regexp/no-super-linear-backtracking': 'error',
'regexp/no-dupe-characters-character-class': 'warn',
'regexp/confusing-quantifier': 'warn',
'regexp/optimal-quantifier-concatenation': 'warn',
// General Security Hotspots (eslint-plugin-security)
'security/detect-non-literal-regexp': 'warn',
'security/detect-child-process': 'error',
'security/detect-new-buffer': 'error',
'security/detect-non-literal-fs-filename': 'off', // CLI tool - dynamic paths are intentional
'security/detect-object-injection': 'off', // Too many false positives
// ===== Code Quality =====
'max-lines': ['error', { max: 200, skipBlankLines: true, skipComments: true }],
'max-params': ['error', { max: 5 }],
complexity: ['error', { max: 20 }],
// ===== Code Style =====
'object-shorthand': ['error', 'always'],
'prefer-destructuring': [
'error',
{
VariableDeclarator: { array: true, object: true },
AssignmentExpression: { array: false, object: false },
},
{ enforceForRenamedProperties: true },
],
// ===== Barrel Files =====
'barrel-files/avoid-barrel-files': 'error',
// ===== ESLint Comments =====
'eslint-comments/no-use': [
'error',
{
allow: ['eslint-disable-next-line', 'eslint-disable'],
},
],
'eslint-comments/require-description': [
'error',
{
ignore: [],
},
],
'eslint-comments/disable-enable-pair': [
'error',
{
allowWholeFile: false,
},
],
// ===== Unicorn Overrides =====
'unicorn/filename-case': ['error', { case: 'camelCase' }],
'unicorn/no-null': 'off', // Allow null - used by external APIs
'unicorn/no-array-callback-reference': 'off', // Callback references are fine and readable
'unicorn/prefer-number-properties': 'off', // isNaN is fine
// ===== SonarJS Overrides =====
'sonarjs/cognitive-complexity': ['error', 35],
'sonarjs/no-nested-template-literals': 'off',
'sonarjs/no-dead-store': 'off', // False positives on loop control variables
'sonarjs/redundant-type-aliases': 'off', // Type aliases improve readability
'sonarjs/no-in-misuse': 'off',
'sonarjs/todo-tag': 'off', // TODO comments are useful
'sonarjs/deprecation': 'off', // Expensive check
'sonarjs/aws-restricted-ip-admin-access': 'off', // Not relevant
// Allow || for default values
'@typescript-eslint/prefer-nullish-coalescing': 'off',
// Allow void expressions in arrow functions
'@typescript-eslint/no-confusing-void-expression': 'off',
// Allow unnecessary conditions (helps with optional chaining)
'@typescript-eslint/no-unnecessary-condition': 'off',
},
},
{
// Editor folder - uses its own tsconfig
files: ['editor/**/*.ts'],
languageOptions: {
parserOptions: {
project: './editor/tsconfig.json',
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
// Disable prefer-destructuring - false positives with renamed destructuring
'prefer-destructuring': 'off',
// Editor components can be larger
'max-lines': 'off',
},
},
// Svelte files configuration
...svelte.configs['flat/recommended'],
{
files: ['editor/**/*.svelte'],
languageOptions: {
parser: svelteParser,
parserOptions: {
parser: tseslint.parser,
project: './editor/tsconfig.json',
tsconfigRootDir: import.meta.dirname,
extraFileExtensions: ['.svelte'],
},
globals: {
document: 'readonly',
globalThis: 'readonly',
},
},
rules: {
// ===== Svelte Possible Errors =====
'svelte/no-at-html-tags': 'error',
'svelte/require-each-key': 'error',
'svelte/valid-each-key': 'error',
// ===== Svelte Security =====
'svelte/no-target-blank': 'error',
// ===== Svelte Best Practices =====
'svelte/button-has-type': 'error',
'svelte/no-ignored-unsubscribe': 'error',
'svelte/require-stores-init': 'error',
// ===== Svelte Stylistic =====
'svelte/prefer-class-directive': 'warn', // Prefer class:active over ternary
'svelte/prefer-style-directive': 'off', // Too noisy for dynamic positioning
'svelte/shorthand-attribute': 'error',
'svelte/shorthand-directive': 'error',
'svelte/spaced-html-comment': 'error',
'svelte/sort-attributes': 'off', // Personal preference
// ===== Disable rules that conflict with Svelte =====
'import/no-mutable-exports': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off', // Svelte bindings cause issues
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-argument': 'off', // Svelte #each type inference issues
'@typescript-eslint/no-unsafe-return': 'off', // Svelte #each type inference issues
// Svelte uses PascalCase for component files
'unicorn/filename-case': ['error', { case: 'pascalCase' }],
// Allow Props abbreviation in Svelte - common pattern
'unicorn/prevent-abbreviations': [
'error',
{ replacements: { props: false, e: { event: true } } },
],
// Disable prefer-destructuring - false positives with svelte-eslint-parser
'prefer-destructuring': 'off',
// Editor components can be larger
'max-lines': 'off',
},
},
{
// Vue integration
files: ['integrations/vue/**/*.ts', 'integrations/vue/**/*.vue'],
languageOptions: {
parserOptions: {
project: './integrations/vue/tsconfig.app.json',
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
// Vue files use PascalCase
'unicorn/filename-case': ['error', { cases: { pascalCase: true, camelCase: true } }],
// Disable rules that conflict with Vue
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
},
},
{
// React integration
files: ['integrations/react/**/*.ts', 'integrations/react/**/*.tsx'],
languageOptions: {
parserOptions: {
project: './integrations/react/tsconfig.app.json',
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
// React files use PascalCase for components
'unicorn/filename-case': ['error', { cases: { pascalCase: true, camelCase: true } }],
},
},
{
// Ignore generated files, config files, and tests (tests only need to pass typecheck)
ignores: [
'**/node_modules/**',
'**/dist/**',
'*.config.js',
'*.config.ts',
'editor/*.config.ts',
'integrations/*/*.config.ts',
'**/*.test.ts',
'**/*.test.tsx',
'**/tests/**',
'**/setupTests.ts',
],
}
);