六类问题分组打印——每类有不同修复方向,分开看更清晰。
(items: list[dict])
| 2436 | |
| 2437 | |
| 2438 | def fmt_source_issues(items: list[dict]): |
| 2439 | """六类问题分组打印——每类有不同修复方向,分开看更清晰。""" |
| 2440 | if not items: |
| 2441 | print("✅ 所有页面 source_count / sources 数组 / 正文引用 / analysis-comparison 类型最低 source 要求均合规") |
| 2442 | return |
| 2443 | by_type = {} |
| 2444 | for it in items: |
| 2445 | by_type.setdefault(it["issue_type"], []).append(it) |
| 2446 | titles = { |
| 2447 | "count-mismatch": "source_count 字段值与 sources 数组长度不一致", |
| 2448 | "missing-source": "论断型页面 source_count=0 但未标 #to-be-updated/stub", |
| 2449 | "analysis-undersourced": "analysis/comparison 类型需 source_count ≥ 2(跨文档综合需 ≥ 2 个来源)", |
| 2450 | "source-summary-mismatch": "source_summary 应绑定恰好 1 个 raw 来源", |
| 2451 | "broken-source-link": "sources 数组中的链接目标文件不存在", |
| 2452 | "declared-but-uncited": "声明了 sources 但正文无 anchor 级引用([[raw/...]] / [[*#^*]])", |
| 2453 | } |
| 2454 | total = len(items) |
| 2455 | print(f"⚠️ 发现 {total} 处 source_count 问题:\n") |
| 2456 | # 按 issue_type 顺序固定输出,便于人眼扫读 |
| 2457 | ordering = ( |
| 2458 | "count-mismatch", |
| 2459 | "missing-source", |
| 2460 | "analysis-undersourced", |
| 2461 | "source-summary-mismatch", |
| 2462 | "broken-source-link", |
| 2463 | "declared-but-uncited", |
| 2464 | ) |
| 2465 | for key in ordering: |
| 2466 | group = by_type.get(key) |
| 2467 | if not group: |
| 2468 | continue |
| 2469 | print(f"━━ {titles[key]}({len(group)} 处)━━\n") |
| 2470 | for it in group: |
| 2471 | print(f" [{it['type']}] {it['path']} ({it['title']})") |
| 2472 | print(f" 声明 source_count: {it['declared_count']} vs 实际 sources[] 长度: {it['actual_len']}") |
| 2473 | if it.get("detail"): |
| 2474 | print(f" 详情: {it['detail']}") |
| 2475 | print(f" 修复: {it['suggestion']}") |
| 2476 | print() |
| 2477 | |
| 2478 | |
| 2479 | def fmt_index_mismatches(items: list[dict]): |