diff --git a/.vscode/settings.json b/.vscode/settings.json index ff13cfa9c..993b52039 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -38,7 +38,7 @@ // lint && format "oxc.enable": true, - "oxc.typeAware": false, + "oxc.typeAware": true, "oxc.configPath": "oxlint.config.ts", "oxc.fmt.configPath": "oxfmt.config.ts", "eslint.useFlatConfig": true, diff --git a/apps/backend-mock/nitro.config.ts b/apps/backend-mock/nitro.config.ts index c0fc13e2e..9cc3acdb2 100644 --- a/apps/backend-mock/nitro.config.ts +++ b/apps/backend-mock/nitro.config.ts @@ -1,3 +1,5 @@ +import { defineNitroConfig } from 'nitropack/config'; + import errorHandler from './error'; process.env.COMPATIBILITY_DATE = new Date().toISOString(); diff --git a/apps/backend-mock/tsconfig.json b/apps/backend-mock/tsconfig.json index 43008af1c..25280017a 100644 --- a/apps/backend-mock/tsconfig.json +++ b/apps/backend-mock/tsconfig.json @@ -1,3 +1,10 @@ { - "extends": "./.nitro/types/tsconfig.json" + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@vben/tsconfig/node.json", + "compilerOptions": { + "paths": { + "~/*": ["./*"] + } + }, + "exclude": ["node_modules", "dist", ".nitro"] } diff --git a/internal/lint-configs/eslint-config/package.json b/internal/lint-configs/eslint-config/package.json index c0ce7615f..c59d4d46e 100644 --- a/internal/lint-configs/eslint-config/package.json +++ b/internal/lint-configs/eslint-config/package.json @@ -28,7 +28,6 @@ }, "dependencies": { "@eslint/js": "catalog:", - "@typescript-eslint/eslint-plugin": "catalog:", "@typescript-eslint/parser": "catalog:", "@vben/oxlint-config": "workspace:*", "eslint": "catalog:", @@ -36,7 +35,6 @@ "eslint-plugin-n": "catalog:", "eslint-plugin-perfectionist": "catalog:", "eslint-plugin-pnpm": "catalog:", - "eslint-plugin-unicorn": "catalog:", "eslint-plugin-unused-imports": "catalog:", "eslint-plugin-vue": "catalog:", "eslint-plugin-yml": "catalog:", diff --git a/internal/lint-configs/eslint-config/src/configs/index.ts b/internal/lint-configs/eslint-config/src/configs/index.ts index 4ed3ea61e..c1c2b4c91 100644 --- a/internal/lint-configs/eslint-config/src/configs/index.ts +++ b/internal/lint-configs/eslint-config/src/configs/index.ts @@ -5,6 +5,5 @@ export * from './node'; export * from './perfectionist'; export * from './pnpm'; export * from './typescript'; -export * from './unicorn'; export * from './vue'; export * from './yaml'; diff --git a/internal/lint-configs/eslint-config/src/configs/typescript.ts b/internal/lint-configs/eslint-config/src/configs/typescript.ts index 5e4157cf2..2f1e21636 100644 --- a/internal/lint-configs/eslint-config/src/configs/typescript.ts +++ b/internal/lint-configs/eslint-config/src/configs/typescript.ts @@ -2,24 +2,17 @@ import type { Linter } from 'eslint'; import { interopDefault } from '../util'; -const rulesCoveredByOxlint = new Set([ - '@typescript-eslint/ban-ts-comment', - '@typescript-eslint/no-non-null-assertion', - '@typescript-eslint/no-unused-expressions', - '@typescript-eslint/no-unused-vars', - '@typescript-eslint/triple-slash-reference', -]); - +/** + * @typescript-eslint 的规则已迁移到 oxlint(typescript 插件)。 + * 这里仅保留 TS 解析器,供其它 eslint 插件(perfectionist、n 等)解析 TS/TSX 文件。 + * 因不再有类型感知规则,已移除 parserOptions.project,eslint 解析更快。 + * + * 注意:移除 @typescript-eslint 插件后,unused-imports/no-unused-vars 会退回核心实现, + * 无法识别 TS 类型签名里的形参(会误报)。故对 TS/TSX/Vue 统一关闭该规则, + * 未使用变量改由 oxlint 的 no-unused-vars(类型感知)负责。 + */ export async function typescript(): Promise { - const [pluginTs, parserTs] = await Promise.all([ - interopDefault(import('@typescript-eslint/eslint-plugin')), - interopDefault(import('@typescript-eslint/parser')), - ] as const); - const strictRules = Object.fromEntries( - Object.entries(pluginTs.configs.strict?.rules ?? {}).filter( - ([ruleName]) => !rulesCoveredByOxlint.has(ruleName), - ), - ); + const parserTs = await interopDefault(import('@typescript-eslint/parser')); return [ { @@ -27,30 +20,23 @@ export async function typescript(): Promise { languageOptions: { parser: parserTs, parserOptions: { - createDefaultProgram: false, ecmaFeatures: { jsx: true, }, ecmaVersion: 'latest', extraFileExtensions: ['.vue'], jsxPragma: 'React', - project: './tsconfig.*.json', sourceType: 'module', }, }, - plugins: { - '@typescript-eslint': pluginTs as any, - }, rules: { - ...pluginTs.configs['eslint-recommended']?.overrides?.[0]?.rules, - ...strictRules, - // '@typescript-eslint/consistent-type-definitions': ['warn', 'interface'], - '@typescript-eslint/consistent-type-definitions': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-namespace': 'off', - '@typescript-eslint/no-use-before-define': 'off', + 'unused-imports/no-unused-vars': 'off', + }, + }, + { + // Vue `