Просмотр исходного кода

chore(lint): ban optional-chaining in runtime code (#14516)

edison 1 месяц назад
Родитель
Сommit
a25c6c1720
3 измененных файлов с 46 добавлено и 50 удалено
  1. 38 49
      .oxlintrc.json
  2. 1 0
      packages/runtime-core/src/devtools.ts
  3. 7 1
      packages/runtime-core/src/warning.ts

+ 38 - 49
.oxlintrc.json

@@ -1,6 +1,5 @@
 {
   "$schema": "./node_modules/oxlint/configuration_schema.json",
-  "plugins": [],
   "categories": {
     "correctness": "off"
   },
@@ -31,10 +30,6 @@
           "module",
           "require"
         ],
-        "oxc/no-const-enum": "error",
-        "oxc/no-rest-spread-properties": "error",
-        "oxc/no-async-await": "error",
-        "oxc/no-optional-chaining": "error",
         "sort-imports": [
           "error",
           {
@@ -50,47 +45,7 @@
           }
         ],
         "@typescript-eslint/no-import-type-side-effects": "error"
-      },
-      "plugins": ["typescript"]
-    },
-    {
-      "files": [
-        "**/__tests__/**",
-        "packages-private/dts-test/**",
-        "packages-private/dts-build-test/**"
-      ],
-      "rules": {
-        "no-console": "off",
-        "no-restricted-globals": "off",
-        "no-unused-expressions": "off",
-        "no-unused-vars": "off",
-        "no-unsafe-optional-chaining": "off",
-        "no-constant-condition": "off",
-        "vitest/no-conditional-tests": "off",
-        "typescript/no-this-alias": "off",
-        "vitest/warn-todo": "off",
-        "typescript/no-non-null-asserted-optional-chain": "off"
-      },
-      "globals": {
-        "suite": "writable",
-        "test": "writable",
-        "describe": "writable",
-        "it": "writable",
-        "expectTypeOf": "writable",
-        "assertType": "writable",
-        "expect": "writable",
-        "assert": "writable",
-        "chai": "writable",
-        "vitest": "writable",
-        "vi": "writable",
-        "beforeAll": "writable",
-        "afterAll": "writable",
-        "beforeEach": "writable",
-        "afterEach": "writable",
-        "onTestFailed": "writable",
-        "onTestFinished": "writable"
-      },
-      "plugins": ["vitest", "typescript"]
+      }
     },
     {
       "files": ["packages/shared/**"],
@@ -99,13 +54,14 @@
       }
     },
     {
-      "files": ["packages/{vue,vue-compat,runtime-dom,runtime-vapor}/**"],
+      "files": ["packages/{vue,vue-compat,runtime-*}/**"],
       "rules": {
-        "no-restricted-globals": ["error", "module", "require"]
+        "no-restricted-globals": ["error", "module", "require"],
+        "oxc/no-optional-chaining": "error"
       }
     },
     {
-      "files": ["packages/{compiler-sfc,compiler-ssr,server-renderer}/**"],
+      "files": ["packages/{compiler-*,server-renderer}/**"],
       "rules": {
         "no-restricted-globals": ["error", "window", "document"],
         "oxc/no-const-enum": "error"
@@ -134,6 +90,39 @@
         ]
       }
     },
+    {
+      "files": [
+        "**/__tests__/**",
+        "packages-private/dts-test/**",
+        "packages-private/dts-build-test/**"
+      ],
+      "rules": {
+        "no-console": "off",
+        "no-restricted-globals": "off",
+        "no-unused-vars": "off",
+        "oxc/no-optional-chaining": "off",
+        "no-restricted-syntax": "off"
+      },
+      "globals": {
+        "suite": "writable",
+        "test": "writable",
+        "describe": "writable",
+        "it": "writable",
+        "expectTypeOf": "writable",
+        "assertType": "writable",
+        "expect": "writable",
+        "assert": "writable",
+        "chai": "writable",
+        "vitest": "writable",
+        "vi": "writable",
+        "beforeAll": "writable",
+        "afterAll": "writable",
+        "beforeEach": "writable",
+        "afterEach": "writable",
+        "onTestFailed": "writable",
+        "onTestFinished": "writable"
+      }
+    },
     {
       "files": [
         "scripts/**",

+ 1 - 0
packages/runtime-core/src/devtools.ts

@@ -63,6 +63,7 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any): void {
     // some envs mock window but not fully
     window.HTMLElement &&
     // also exclude jsdom
+    // oxlint-disable-next-line oxc/no-optional-chaining
     !window.navigator?.userAgent?.includes('jsdom')
   ) {
     const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =

+ 7 - 1
packages/runtime-core/src/warning.ts

@@ -54,7 +54,13 @@ export function warn(msg: string, ...args: any[]): void {
       instance,
       ErrorCodes.APP_WARN_HANDLER,
       [
-        msg + args.map(a => a.toString?.() ?? JSON.stringify(a)).join(''),
+        msg +
+          args
+            .map(a => {
+              const toString = a.toString
+              return toString == null ? JSON.stringify(a) : toString.call(a)
+            })
+            .join(''),
         (instance && instance.proxy) || instance,
         trace
           .map(