refactor(提交): 教师统计路由拆出 submission-statistics.ts,check:routes 支持嵌套挂载
Some checks failed
Deploy / deploy (push) Has been cancelled

- submission.ts 1416 行降到 751 行;统计三条路由拆成子路由,挂在原位置,
  仍排在 /submissions/:id 之前
- check-route-shadowing 原来只认 index.ts 直接挂载,拆分后漏检 3 条(178→175);
  现在按挂载位置展开嵌套的 .route(),恢复 178 条、无遮蔽

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-19 04:40:30 -06:00
parent b5ba56ccd0
commit c228b164cf
3 changed files with 727 additions and 680 deletions

View File

@@ -16,7 +16,8 @@
*
* 加路由时顺手跑一下,比事后靠人眼在 200 多条路由里看出顺序问题可靠。
*
* 局限:靠正则读源码,只认 `xxxRoutes.get("字面量", …)` 这种写法
* 局限:靠正则读源码,只认 `xxxRoutes.get("字面量", …)` 这种写法
* 以及 `xxxRoutes.route("字面量", 子路由)` 的嵌套挂载(按挂载位置展开)。
* 动态拼出来的路径看不见 —— 但本仓库没有那种写法,加的时候请保持。
*/
@@ -74,15 +75,22 @@ function collect(): Route[] {
const file = routerFile.get(router)
if (!file) return []
const text = readFileSync(file, "utf8")
// 直接注册的路由和嵌套挂载(`router.route("/", child)`)放在一起按出现位置排序:
// 子路由挂在哪个位置,它的路由就在哪个位置参与匹配
const pattern = new RegExp(
`${router}\\.(get|post|put|delete|patch)\\(\\s*"([^"]+)"`,
`${router}\\.(get|post|put|delete|patch)\\(\\s*"([^"]+)"|${router}\\.route\\(\\s*"([^"]*)"\\s*,\\s*(\\w+)\\s*\\)`,
"g",
)
return [...text.matchAll(pattern)].map((m) => ({
method: m[1]!.toUpperCase(),
path: (prefix + m[2]!).replace(/\/+/g, "/").replace(/\/$/, "") || "/",
file: file.replace(SRC + "/", ""),
}))
return [...text.matchAll(pattern)].flatMap((m) => {
if (m[4]) return routesOf(m[4], prefix + m[3]!)
return [
{
method: m[1]!.toUpperCase(),
path: (prefix + m[2]!).replace(/\/+/g, "/").replace(/\/$/, "") || "/",
file: file.replace(SRC + "/", ""),
},
]
})
}
// 挂载顺序就是匹配顺序,所以必须按 index.ts 里出现的先后来摊平