Add pkg/report standalone external validation suite and example report

This commit is contained in:
gitea committed 2026-10-15 16:47:26 +08:00
1 parent f9f72fa918
commit f6fe0de286
6 files changed
+939 -6

No files matched your search

+13 -6
View File
@@ -133,18 +133,25 @@ export function validateReportDocument(file: string): ReportValidation {
error("NM003", `${keyword}「${row[1]}」占比 ${decimal(share)}% ≠ ${count.toFixed(0)}/${base.toFixed(0)} = ${(count / base * 100).toFixed(1)}%`)
}
}
let sectionNum = keyword === "失准类型" ? "2" : "3"
// 找到当前大章节的文本范围(从当前 ## 开始到下一个 ## 结束,只在本章节内核验小节)
let chapterText = text
for (let i = table.line - 1; i >= 0; i--) {
const h2Match = lines[i]?.match(/^##\s*(\d+)\./)
if (h2Match) {
sectionNum = h2Match[1]!
if (lines[i]?.match(/^##\s+/)) {
let nextH2Line = lines.length
for (let j = i + 1; j < lines.length; j++) {
if (lines[j]?.match(/^##\s+/)) {
nextH2Line = j
break
}
}
chapterText = lines.slice(i, nextH2Line).join("\n")
break
}
}
// 小节标题里的张数与总览表一致(动态定位所属章节序号,支持章节任意重排)
// 小节标题里的张数与总览表一致(只在本核心章节范围内匹配,不受章节编号与位置影响)
for (const top of tops) {
const escaped = top.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
const match = text.match(new RegExp(`###\\s*${sectionNum}\\.\\d+\\s*${escaped}[^(]*((\\d+)\\s*张`))
const match = chapterText.match(new RegExp(`###\\s*\\S*\\s*${escaped}[^(\\n]*((\\d+)\\s*张`))
if (match && top.count !== null && Number(match[1]) !== top.count) error(tag, `${top.name} 小节标题写 ${match[1]} 张,总览表写 ${top.count.toFixed(0)} 张`)
}
}