[P1][CR-T5] 引入 ESLint 最小规则集,用静态检查固化前后端分层、确定性与反静默兜底约束 #537
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
问题描述
仓库目前只开了
tsc --noEmit,没有任何 Linter(ESLint / Biome)或 Formatter(package.json:54-61)。本次评审发现的多类结构性问题——后端反向 import 前端、模拟层混入Math.random/Date.now/performance.now、未处理的悬空 Promise、any泛滥、循环依赖、new Function——都是 TypeScript 编译器管不到、但一条 ESLint 规则就能在提交前拦住的。如果不把这些边界写成自动化门禁,修完一轮后很快又会在新代码里回潮。
证据
devDependencies只有@types/node、@vitest/coverage-v8、tsx、typescript、vite、vitest。npm run typecheck和npm test。src/中显式any约 620 处(其中skill-caster.ts113 处、item-bridge.ts71 处,见 #527);src/scene/backend/*反向 importsrc/ui/*、src/render/*、src/scene/frontend/*(见 #526);Math.random、Date.now、performance.now(见 #523);.catch(() => {})(见 #529、#530);new Function动态求值(见 #534);vitestExpect(true).toBe(true)(见 #535)。根因
项目早期以高吞吐移植功能和通过类型检查为首要目标,没有把
AGENTS.md中的架构红线(前后端分层、1.13c 确定性、禁止静默兜底)转化为可执行的静态分析规则。修复指南
使用 ESLint v9 Flat Config(
eslint.config.mjs)+typescript-eslint,只开高信噪比、直接对应本次评审问题的最小规则集,不做纯风格噪音检查:no-restricted-importssrc/game/**、src/scene/backend/**、src/sim/**、src/net/**src/ui/**、src/render/**、src/scene/frontend/**、src/frontend/**import/no-cycle(或eslint-plugin-import-x)src/**no-restricted-properties/no-restricted-globalssrc/game/**、src/scene/backend/**、src/net/**Math.random、Date.now、performance.now(注:src/sim/loop.ts的帧率计时属于合法用途,单独放到src/sim/豁免)@typescript-eslint/no-floating-promises、@typescript-eslint/no-misused-promisessrc/**void标注并接入生命周期@typescript-eslint/no-explicit-anysrc/**warn并逐步清零,已清零目录设为errorno-new-func、no-evalsrc/**new Function与eval@typescript-eslint/no-shadowsrc/**、tests/**tests/net.test.ts里外层/内层同名problems、checks遮蔽no-restricted-syntax(禁止expect(true).toBe(true)/vitestExpect(true).toBe(true))tests/**no-restricted-syntax(审计?? <NumericLiteral>)src/game/**warn/ 审计脚本运行,配合 #524 清理数据表缺失字段的静默魔法数字兜底落地步骤:
eslint、@eslint/js、typescript-eslint、eslint-plugin-import-x。eslint.config.mjs,对已经干净的目录直接开error,对尚在迁移中的目录(如 #526、#527 还没拆完的文件)用精确到文件列表的 override 暂时标为warn,每完成一个子 issue 就把对应文件从 override 列表移除。package.json中加入"lint": "eslint src scripts tests",并写入.gitea/workflows/ci.yml与AGENTS.md§5 质量门禁。验收标准
npm run lint可运行并纳入package.json与.gitea/workflows/ci.yml。src/game/或src/scene/backend/中尝试写import ... from '../ui/...'、Math.random()、Date.now()、new Function(...)或悬空 Promise 时,npm run lint立即以error退出。tests/中尝试写expect(true).toBe(true)或遮蔽外层同名变量时,npm run lint立即以error退出。npm run typecheck0 error;npm run lint0 error;npx vitest run全部通过。相关
any。new Function。