feat: ESLint 自定义规则增强 — 空函数和 catch 模式的项目修复指引

This commit is contained in:
2026-06-01 16:23:04 +08:00
parent 60843f7dbf
commit df5b60eb53
3 changed files with 162 additions and 0 deletions

View File

@@ -6,6 +6,9 @@ import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import tseslint from "typescript-eslint";
import { enforceCatchType } from "./eslint-rules/enforce-catch-type.js";
import { noEmptyFunction } from "./eslint-rules/no-empty-function.js";
const noDirectConsoleMessage =
"后端运行时代码禁止直接使用 console.*;请通过注入的 Logger 实例输出日志,配置加载失败前使用 createConsoleFallback()。";
@@ -23,6 +26,7 @@ export default tseslint.config(
".agents/**",
"bun.lock",
"data/**",
"eslint-rules/**",
],
},
js.configs.recommended,
@@ -47,14 +51,38 @@ export default tseslint.config(
"@typescript-eslint/array-type": ["error", { default: "array-simple" }],
"@typescript-eslint/consistent-type-assertions": ["error", { assertionStyle: "as" }],
"@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports" }],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
"@typescript-eslint/only-throw-error": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"import/no-unresolved": ["error", { ignore: ["^bun:"] }],
"no-restricted-syntax": [
"error",
{
message:
"禁止 throw 字面量。项目约定只允许 throw new Error(...) 或 throw new AppError(msg, statusCode)。Re-throw 已捕获的 Error 实例时使用 throw e。",
selector: "ThrowStatement > Literal",
},
],
"no-undef": "off",
},
},
{
files: ["src/**/*.{ts,tsx}"],
plugins: {
local: {
rules: {
"enforce-catch-type": enforceCatchType,
"no-empty-function": noEmptyFunction,
},
},
},
rules: {
"local/enforce-catch-type": "warn",
"local/no-empty-function": "error",
},
},
{
files: ["eslint.config.js"],
rules: {