-
Notifications
You must be signed in to change notification settings - Fork 504
Expand file tree
/
Copy path.oxlintrc.json
More file actions
689 lines (683 loc) · 23.6 KB
/
.oxlintrc.json
File metadata and controls
689 lines (683 loc) · 23.6 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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"jsPlugins": [
"@cspell/eslint-plugin",
"eslint-plugin-import-path",
"eslint-plugin-props-checker",
"eslint-plugin-ban",
"eslint-plugin-prettier",
{ "name": "import-js", "specifier": "eslint-plugin-import" },
"./development/plugins/eslint-plugin-onekey.js"
],
"extends": ["eslint-config-prettier"],
"plugins": [
"unicorn",
"typescript",
"oxc",
"react",
"react_perf",
"import",
"jest",
"jsx-a11y"
],
// NOTE: JavaScript ESLint plugins (experimental feature) are not used yet
// because some plugin configurations are not compatible with oxlint
// https://oxc.rs/docs/guide/usage/linter/migrate-from-eslint.html#local-custom-eslint-plugins
// The following plugins remain in ESLint:
// - eslint-plugin-ban
// - eslint-plugin-import-path
// - eslint-plugin-use-effect-no-deps
// - eslint-plugin-props-checker
"categories": {
// Code that is outright wrong or useless
"correctness": "error",
// Code that is most likely wrong or useless
"suspicious": "warn",
// Lints which are rather strict
"pedantic": "off",
// Code that could be written in a more performant way
"perf": "warn",
// Code that should be written in a more idiomatic way
"style": "off",
// Lints which prevent the use of language and library features
"restriction": "off"
},
"rules": {
"max-classes-per-file": ["error", 1],
"prettier/prettier": ["error"],
"@cspell/spellchecker": [
"warn",
{
"ignoreImports": true,
"ignoreImportProperties": true,
"checkJSXText": true,
"checkComments": true,
"checkStrings": false,
"checkIdentifiers": true,
"autoFix": false
}
],
"import-path/parent-depth": ["error", 3],
"import-path/forbidden": [
"error",
[
{
"match": "/index$",
"message": "Index on the end of path is redundant"
}
]
],
// NOTE: This rule stays in ESLint because oxlint jsPlugins is experimental
"props-checker/validator": [
"error",
{
"props": [
{
"propName": "onPress",
"components": [
{ "component": "Stack", "dependOn": "pressStyle" },
{ "component": "XStack", "dependOn": "pressStyle" },
{ "component": "YStack", "dependOn": "pressStyle" }
]
},
{ "propName": "accessible", "components": ["TextInput"] }
]
}
],
"ban/ban": [
"error",
{
"name": ["*", "toLocaleUpperCase"],
"message": "Prefer use toUpperCase"
},
{
"name": ["*", "toLocaleLowerCase"],
"message": "Prefer use toLowerCase"
},
{
"name": ["InteractionManager", "runAfterInteractions"],
"message": "Use timerUtils.setTimeoutPromised instead of InteractionManager.runAfterInteractions"
}
],
// ============================================
// ESLint core rules
// ============================================
// NOTE: Changed to warn because oxlint doesn't fully support caughtErrorsIgnorePattern
"no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_",
"ignoreRestSiblings": true
}
],
"no-debugger": "error",
"no-eval": "error",
"radix": "error",
// Migrated from ESLint airbnb/wesbos presets
"eqeqeq": "warn",
"no-self-compare": "error",
"no-fallthrough": "error",
"no-redeclare": "error",
"no-useless-constructor": "error",
"no-new-wrappers": "error",
"no-var": "error",
"prefer-const": "warn",
"prefer-template": "warn",
"no-empty": "error",
// Disabled: 249 intentional empty functions (context defaults, platform stubs, event placeholders)
"no-empty-function": "off",
"no-throw-literal": "error",
"no-param-reassign": "error",
"no-return-assign": "error",
"guard-for-in": "error",
"no-inner-declarations": "error",
"no-misleading-character-class": "error",
"no-case-declarations": "error",
"no-constructor-return": "error",
"no-else-return": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-iterator": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-loop-func": "error",
"no-new": "error",
"no-new-func": "error",
"no-proto": "error",
"no-script-url": "error",
"no-sequences": "error",
"no-useless-concat": "error",
"no-useless-return": "error",
"prefer-promise-reject-errors": "warn",
"no-useless-computed-key": "error",
"prefer-numeric-literals": "error",
"prefer-rest-params": "error",
"prefer-spread": "warn",
"symbol-description": "error",
"no-label-var": "error",
"no-template-curly-in-string": "error",
"no-plusplus": "error",
"no-nested-ternary": "error",
// Sort imports (migrated from ESLint)
"sort-imports": [
"error",
{
"ignoreMemberSort": false,
"ignoreDeclarationSort": true
}
],
// Restricted imports (migrated from @typescript-eslint/no-restricted-imports)
"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": ["@onekeyfe/hd-core"],
"message": "using `const {} = await CoreSDKLoader()` instead",
"allowTypeImports": true
},
{
"group": ["**/localDbInstance", "**/localDbInstance.native"],
"message": "import localDbInstance directly is not allowed, use localDb instead"
},
{
"group": ["@onekeyhq/desktop/app/i18n"],
"message": "import ETranslations from \"@onekeyhq/shared/src/locale\" instead"
},
{
"group": ["**/v4localDbInstance.native"],
"message": "import v4localDbInstance.native directly is not allowed, use v4localDbInstance instead"
},
{
"group": [
"**/v4ToV5Migration",
"v4ToV5Migration/**",
"**/v4ToV5Migration/**"
],
"message": "import **/v4ToV5Migration/** not allowed"
},
{
"group": ["**/v4localDBStoreNames.native"],
"message": "import v4localDBStoreNames instead"
},
{
"group": ["jotai"],
"importNames": ["useAtom", "useSetAtom", "atom"],
"message": "Direct import of useAtom/useSetAtom from jotai is not allowed. Use contextAtom or globalAtom instead."
}
]
}
],
// ============================================
// React rules (matching ESLint config)
// ============================================
"react/jsx-key": "error",
"react/jsx-no-duplicate-props": "error",
"react/no-children-prop": "error",
"react/no-string-refs": "error",
"react/no-direct-mutation-state": "error",
// react-hooks/rules-of-hooks (migrated from ESLint)
"react/rules-of-hooks": "error",
"react/jsx-no-undef": "error",
"react/jsx-pascal-case": "error",
"react/self-closing-comp": "error",
"react/no-unknown-property": "error",
// react-hooks/exhaustive-deps equivalent
"react/exhaustive-deps": [
"error",
{
"additionalHooks": "(usePromiseResult|useAsyncCall|useUpdateEffect|useDeepCompareEffect)"
}
],
"react/jsx-curly-brace-presence": [
"error",
{ "props": "never", "children": "never" }
],
// react_perf rules — enabled only for packages/components (see overrides)
"react_perf/jsx-no-new-function-as-prop": "off",
"react_perf/jsx-no-new-object-as-prop": "off",
"react_perf/jsx-no-new-array-as-prop": "off",
"react_perf/jsx-no-jsx-as-prop": "off",
"typescript/no-unsafe-type-assertion": "off",
"typescript/no-unnecessary-boolean-literal-compare": "off",
// ============================================
// TODO: will enabled in next version after fixing issues
"typescript/no-base-to-string": "off",
"typescript/no-unsafe-enum-comparison": "off",
"typescript/no-meaningless-void-operator": "off",
"typescript/no-unnecessary-type-arguments": "off",
"typescript/no-duplicate-type-constituents": "off",
"typescript/no-redundant-type-constituents": "off",
"typescript/require-array-sort-compare": "off",
"typescript/no-unnecessary-template-expression": "error",
"typescript/no-misused-spread": "error",
"typescript/no-array-delete": "error",
"typescript/no-misused-promises": ["error", { "checksVoidReturn": false }],
// Type-aware rules migrated from ESLint
"typescript/no-unsafe-return": "error",
"typescript/no-unsafe-call": "error",
"typescript/await-thenable": "error",
"typescript/no-empty-object-type": "error",
"typescript/no-unsafe-function-type": "error",
// ESLint core rules migrated
"no-continue": "error",
// React rules migrated
"react/display-name": "warn",
// Jest rules migrated
"jest/no-identical-title": "error",
// jsx-a11y rules migrated from ESLint
"jsx-a11y/click-events-have-key-events": "error",
"jsx-a11y/no-static-element-interactions": "error",
"jsx-a11y/media-has-caption": "error",
// Disabled: not applicable for React Native / desktop app context
"jsx-a11y/no-autofocus": "off",
"jsx-a11y/prefer-tag-over-role": "off",
"jsx-a11y/heading-has-content": "off",
"jsx-a11y/anchor-has-content": "off",
"jsx-a11y/anchor-is-valid": "off",
// ============================================
// TypeScript rules (matching ESLint config)
// ============================================
// Force awaited promise call, explicit add `void` if don't want await
"typescript/no-floating-promises": ["error"],
"typescript/consistent-type-imports": [
"error",
{
"disallowTypeAnnotations": false
}
],
// Variable shadowing detection
"no-shadow": [
"error",
{
"ignoreTypeValueShadow": true,
"ignoreFunctionTypeParameterNameValueShadow": true,
"hoist": "functions-and-types",
"builtinGlobals": false
}
],
// Disallow use before define
"no-use-before-define": [
"error",
{
"functions": false,
"classes": true,
"variables": true,
"allowNamedExports": true,
"ignoreTypeReferences": true
}
],
// ============================================
// Unicorn rules (matching ESLint config)
// ============================================
"unicorn/numeric-separators-style": "error",
// ============================================
// Import rules
// ============================================
"import/no-cycle": "error",
"import/export": "error",
"import/first": "error",
"import/no-amd": "error",
"import/no-duplicates": "error",
"import/no-mutable-exports": "error",
"import/no-self-import": "error",
// Import declaration ordering (via eslint-plugin-import JS plugin)
"import-js/order": [
"error",
{
"groups": [
"builtin",
"internal",
"index",
"external",
"parent",
"sibling",
"object",
"type"
],
"pathGroups": [
{
"pattern": "react",
"group": "builtin",
"position": "before"
},
{
"pattern": "@onekeyhq/**",
"group": "external",
"position": "after"
}
],
"alphabetize": {
"order": "asc",
"caseInsensitive": true
},
"newlines-between": "always",
"pathGroupsExcludedImportTypes": ["builtin"],
"warnOnUnassignedImports": true
}
],
// ============================================
// Jest rules (for test files) - keep off as in ESLint config
// ============================================
"jest/expect-expect": "off",
"jest/no-disabled-tests": "off",
"jest/no-conditional-expect": "off",
"jest/valid-title": "off",
"jest/no-export": "off",
// Require message for toThrow - not enforced in codebase
"jest/require-to-throw-message": "off",
// ============================================
// Disabled rules (too many false positives or not applicable)
// ============================================
// React 17+ with new JSX transform doesn't need React in scope
"react/react-in-jsx-scope": "off",
// Duplicate enum values are intentional in some cases
"typescript/no-duplicate-enum-values": "off",
// new Array() is sometimes needed
"unicorn/no-new-array": "off",
// These import rules have too many false positives
"import/no-named-as-default": "off",
"import/no-named-as-default-member": "off",
// Side-effect imports are valid
"import/no-unassigned-import": "off",
// await in loop is sometimes intentional for sequential processing
"no-await-in-loop": "off",
// Performance suggestions, not errors
"oxc/no-map-spread": "off",
// Accumulating spread in loops - disabled due to many existing usages
"oxc/no-accumulating-spread": "off",
// Event handler patterns vary
"unicorn/prefer-add-event-listener": "off",
// Function scoping is sometimes intentional
"unicorn/consistent-function-scoping": "off",
// Promise.all with await is valid pattern
"unicorn/no-await-in-promise-methods": "off",
// Constant binary expressions are sometimes intentional
"no-constant-binary-expression": "off",
// Useless catch is sometimes for debugging
"no-useless-catch": "off",
// Module default export issues
"import/default": "off",
// Parameter property assignment is valid pattern
"typescript/no-unnecessary-parameter-property-assignment": "off",
// Migrated from ESLint — catches unused expressions (ternary as statement, bare identifiers)
"no-unused-expressions": "error",
// Variables may be assigned later via destructuring or other patterns
"no-unassigned-vars": "off",
// Empty classes are valid as base classes
"typescript/no-extraneous-class": "off",
// window/self usage is valid in browser context
"unicorn/prefer-global-this": "error",
// Empty files may be placeholders
"unicorn/no-empty-file": "off",
// postMessage targetOrigin is optional in some contexts
"unicorn/require-post-message-target-origin": "off",
// Array index keys are acceptable in some list rendering scenarios
"react/no-array-index-key": "off",
// Unsafe optional chaining is valid in some patterns
"no-unsafe-optional-chaining": "off",
// useless length check may be intentional for clarity
"unicorn/no-useless-length-check": "off",
// Invalid remove event listener - some patterns are valid
"unicorn/no-invalid-remove-event-listener": "off",
// Single promise in Promise.all is sometimes intentional
"unicorn/no-single-promise-in-promise-methods": "off",
// prefer-array-find vs filter()[0] - not critical
"unicorn/prefer-array-find": "off",
// instanceof builtins is valid in some cross-realm scenarios
"unicorn/no-instanceof-builtins": "off",
// useless call may be intentional for explicitness
"no-useless-call": "off",
// iframe sandbox - handled differently in this codebase
"react/iframe-missing-sandbox": "off",
// Extending native prototypes is sometimes needed
"no-extend-native": "off",
// Constant conditions may be intentional for development
"no-constant-condition": "off",
// namespace import issues - too many false positives
"import/namespace": "off",
// Allow using Object.assign instead of spread syntax
"prefer-object-spread": "off",
// ============================================
// Custom OneKey rules (JS plugin)
// ============================================
// Enforce OneKeyLocalError/OneKeyError instead of raw Error
"onekey/no-raw-error": "error"
},
// Package-specific rules (migrated from ESLint overrides)
"overrides": [
{
// packages/components - cannot import from kit or kit-bg + react_perf rules
"files": [
"packages/components/src/**/*.ts",
"packages/components/src/**/*.tsx"
],
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": ["@onekeyhq/kit", "@onekeyhq/kit-bg"],
"message": "Please avoid using @onekeyhq/kit and @onekeyhq/kit-bg in this folder",
"allowTypeImports": true
}
]
}
],
"react_perf/jsx-no-new-function-as-prop": "error",
"react_perf/jsx-no-new-object-as-prop": "error",
"react_perf/jsx-no-new-array-as-prop": "error",
"react_perf/jsx-no-jsx-as-prop": "error"
}
},
{
// packages/shared - cannot import from kit, kit-bg, components, or core
"files": ["packages/shared/src/**/*.ts", "packages/shared/src/**/*.tsx"],
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": [
"@onekeyhq/kit",
"@onekeyhq/kit-bg",
"@onekeyhq/components"
],
"message": "Please avoid using @onekeyhq/kit, @onekeyhq/kit-bg, and @onekeyhq/components in this folder",
"allowTypeImports": true
},
{
"group": ["@onekeyhq/core", "@onekeyhq/core/**"],
"message": "shared layer must not value-import from core — only kit-bg may import core. Use import type for types.",
"allowTypeImports": true
}
]
}
]
}
},
{
// packages/kit-bg - cannot import from kit or components, or tamagui
"files": ["packages/kit-bg/src/**/*.ts", "packages/kit-bg/src/**/*.tsx"],
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": ["tamagui"],
"message": "Please avoid using tamagui in this folder",
"allowTypeImports": true
},
{
"group": ["@onekeyhq/kit", "@onekeyhq/components"],
"message": "Please avoid using @onekeyhq/kit and @onekeyhq/components in this folder",
"allowTypeImports": true
}
]
}
]
}
},
{
// packages/kit - cannot import from tamagui, kit-bg internal paths, or core
"files": ["packages/kit/src/**/*.ts", "packages/kit/src/**/*.tsx"],
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": ["tamagui"],
"message": "Please avoid using tamagui in this folder",
"allowTypeImports": true
},
{
"group": [
"@onekeyhq/kit-bg/src/connectors",
"@onekeyhq/kit-bg/src/dbs",
"@onekeyhq/kit-bg/src/endpoints",
"@onekeyhq/kit-bg/src/migrations",
"@onekeyhq/kit-bg/src/offscreens",
"@onekeyhq/kit-bg/src/providers",
"@onekeyhq/kit-bg/src/services",
"@onekeyhq/kit-bg/src/vaults",
"@onekeyhq/kit-bg/src/webembeds"
],
"message": "Please avoid using @onekeyhq/kit-bg internal paths in this folder",
"allowTypeImports": true
},
{
"group": ["@onekeyhq/core", "@onekeyhq/core/**"],
"message": "kit layer must not value-import from core — use shared re-exports or kit-bg service RPC. Use import type for types.",
"allowTypeImports": true
}
]
}
]
}
},
{
// packages/core - cannot import from kit, kit-bg, components, or tamagui
"files": ["packages/core/src/**/*.ts", "packages/core/src/**/*.tsx"],
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": [
"tamagui",
"@onekeyhq/kit",
"@onekeyhq/kit-bg",
"@onekeyhq/components"
],
"message": "Please avoid using tamagui, @onekeyhq/kit, @onekeyhq/kit-bg, @onekeyhq/components in this folder",
"allowTypeImports": true
}
]
}
]
}
},
{
// Development scripts, test tooling, and native modules — OneKeyLocalError doesn't apply
"files": [
"development/**/*.js",
"development/**/*.ts",
"development/**/*.mjs",
"apps/*/e2e/**/*.js",
"apps/*/harness/**/*.ts",
"apps/*/harness/**/*.mjs",
"apps/*/plugins/**/*.js",
"apps/desktop/native-modules/**/*.js"
],
"rules": {
"onekey/no-raw-error": "off"
}
},
{
// Test files - relax some rules
"files": ["test/**/*.js", "test/**/*.ts", "**/*.test.ts"],
"rules": {}
},
{
// JS/JSX files - disable TypeScript-specific rules
"files": ["**/*.js", "**/*.jsx"],
"rules": {
"typescript/no-floating-promises": "off",
"typescript/consistent-type-imports": "off",
"typescript/no-duplicate-enum-values": "off",
"typescript/no-extraneous-class": "off",
"typescript/no-unnecessary-parameter-property-assignment": "off",
"typescript/unbound-method": "off",
"typescript/no-unsafe-type-assertion": "off",
"typescript/no-implied-eval": "off",
"typescript/no-base-to-string": "off",
"typescript/no-unnecessary-template-expression": "off",
"typescript/restrict-template-expressions": "off",
"typescript/require-array-sort-compare": "off",
"typescript/no-unsafe-call": "off",
"typescript/no-unsafe-return": "off",
"typescript/no-unsafe-function-type": "off",
"typescript/no-empty-object-type": "off"
}
}
],
"settings": {
"react": {
"formComponents": [],
"linkComponents": [],
"version": "19.1"
},
"jsx-a11y": {
"polymorphicPropName": null,
"components": {},
"attributes": {}
},
"jsdoc": {
"ignorePrivate": false,
"ignoreInternal": false,
"ignoreReplacesDocs": true,
"overrideReplacesDocs": true,
"augmentsExtendsReplacesDocs": false,
"implementsReplacesDocs": false,
"exemptDestructuredRootsFromChecks": false,
"tagNamePreference": {}
},
"vitest": {
"typecheck": false
}
},
"env": {
"browser": true,
"es6": true,
"webextensions": true,
"serviceworker": true,
"worker": true
},
"globals": {},
// Ignore patterns matching .eslintrc.js ignorePatterns
"ignorePatterns": [
"*.wasm.bin",
".worktree/**",
".claude/worktrees/**",
"@types/globals.d.ts",
"apps/desktop/public/static/js-sdk*",
"packages/components/src/primitives/Icon/Icons.tsx",
"packages/components/src/primitives/Icon/react/*",
"packages/shared/src/modules3rdParty/stripe-v3/*",
"packages/core/src/chains/xmr/sdkXmr/moneroCore/moneroCore.js",
"packages/shared/src/locale/enum/translations.ts",
"packages/shared/src/locale/localeJsonMap.ts",
"packages/shared/src/locale/json/*",
"node_modules/**",
".history/**",
"dist/**",
"build/**"
]
}