问题域/PD-500

静态代码分析

Static Code Analysis

多维度静态分析检测代码质量问题,覆盖 dead code、复杂度、重复、命名等

子问题

1.Dead code detection

2.Complexity analysis

3.Duplication detection

4.Naming convention enforcement

5.Dependency cycle detection

6.God class/component detection via multi-rule threshold

7.Orphaned file detection with dynamic import awareness

8.Cross-language security pattern scanning

9.Single-use abstraction inlining candidates

10.Architectural coupling and boundary violation detection

11.四模式评分分离:lenient/strict/verified_strict 各有不同 wontfix 处理策略,需明确语义

12.维度停滞检测:3+ 次扫描分数变化 ≤ 0.5 时识别停滞并建议切换维度

13.主观评分反作弊:检测评分聚集在目标分数附近的 gaming 行为并自动 reset

14.Headline 阶段适配:不同 phase 需要不同语气(regression 安抚、stagnation 激励、maintenance 警惕)

15.Scorecard PIL 延迟导入:图片生成依赖 Pillow 但大多数 CLI 命令不需要,需 deferred import

各项目的解法1 solutions

Signals

横向对比

维度Desloppify
检测器架构29+ 检测器统一注册表,frozen dataclass 元数据 + 运行时插件扩展
AST 解析tree-sitter 27 语言 S-expression 查询,scan-scoped parse cache
误报过滤6-zone 策略矩阵(skip/downgrade/exclude_from_score),首条规则匹配
优先级分类T1-T4 四级 Tier + action_type 四类修复难度 + needs_judgment LLM 标记
重复检测Union-Find 聚类 + SequenceMatcher 三级剪枝(LOC 窗口/最大比率/渐进式)
安全检测五规则行扫描器(secret format/name/random/crypto/log),SecurityRule dataclass
追踪方式四层评分时间序列(overall/objective/strict/verified_strict)+ 维度级快照
数据粒度维度级:每个维度独立 score/strict/checks/issues/tier/detectors
持久化state.json 单文件,scan_history 滚动窗口 20 条
可视化PIL 渲染 landscape PNG scorecard,2x Retina 缩放,三色分级
评估指标设计30+ detectors → N dimensions,tier 加权聚合,lenient/strict 双轨
评估门控strict_score 目标值(默认 95),gap/state/warning 结构化输出
去重决策透明wontfix 债务分析:overall_gap/worst_dimension/trend 三维度量化
日志格式NarrativeResult TypedDict:phase/headline/risk_flags/actions 结构化诊断
代码膨胀度量dimension_scores 按 File health/Code quality/Duplication 等维度追踪
错误驱动发现7 阶段检测(regression/stagnation/early_momentum 等)驱动行动建议
安全审计security findings 作为 headline 前缀优先展示,独立于其他维度
版本追踪scan_count + tool_hash 记录扫描工具版本变化
指标采集每次 scan 后 _append_scan_history 自动采集 4 种分数 + diff 指标
反作弊完整性SubjectiveIntegrity 检测主观评分聚集,自动 reset 可疑维度

最佳实践

1.Zone-aware filtering to reduce false positives

2.Tier-based severity classification for prioritization

3.Union-Find clustering to reduce N² duplicate pairs to cluster-level findings

4.Three-level pruning (LOC window + max ratio + progressive SequenceMatcher) for near-duplicate detection

5.Frozen dataclass detector registry with runtime plugin extension

6.AST-aware body normalization stripping comments and logs before hash comparison

7.Five-pattern zone rule matching (directory/suffix/prefix/exact/substring)

8.scan_history 滚动窗口 20 条:足够检测趋势(regression 需 2 条、stagnation 需 3 条),不会膨胀 state 文件

9.维度级快照写入 scan_history:每条记录包含所有维度的 score+strict,支持维度粒度的趋势分析

10.NarrativeResult 输出 why_now 字段:不仅告诉用户做什么,还解释为什么现在做

11.Risk flags 按 severity 排序输出:critical > high > medium > low > info,确保最严重问题最先展示