ln-610-code-comments-auditor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode Comments Auditor
代码注释审计工具
Audit code comments and docstrings quality. Universal for any tech stack.
审计代码注释和文档字符串的质量。适用于任何技术栈。
Purpose
用途
- Verify comments explain WHY, not obvious WHAT
- Check comment density (15-20% ratio)
- Detect forbidden content (dates, author names, historical notes)
- Validate docstrings match function signatures
- Ensure comments match current code state
- Identify legacy comments and commented-out code
- 验证注释解释的是WHY(原因),而非显而易见的WHAT(内容)
- 检查注释密度(15-20%的比例)
- 检测禁用内容(日期、作者姓名、历史记录)
- 验证文档字符串与函数签名匹配
- 确保注释与当前代码状态一致
- 识别遗留注释和被注释掉的代码
Invocation
调用方式
- Direct: User invokes for code comment quality review
- Pipeline: Called by ln-100-documents-pipeline (Phase 5, if auditComments=true)
- 直接调用: 用户发起代码注释质量审查请求
- 流水线调用: 由ln-100-documents-pipeline调用(第5阶段,当auditComments=true时)
Workflow
工作流程
- Scan: Find all source files (auto-detect tech stack)
- Extract: Parse inline comments + docstrings/JSDoc
- Audit: Run 6 category checks (see Audit Categories below)
- Score: Calculate X/10 per category
- Report: Output findings and recommended actions
- 扫描: 查找所有源文件(自动检测技术栈)
- 提取: 解析行内注释 + 文档字符串/JSDoc
- 审计: 执行6个类别的检查(见下方审计类别)
- 评分: 计算每个类别的X/10分数
- 报告: 输出问题发现和建议操作
Audit Categories
审计类别
| # | Category | What to Check |
|---|---|---|
| 1 | WHY not WHAT | Comments explain rationale, not obvious code behavior; no restating code |
| 2 | Density (15-20%) | Comment-to-code ratio within range; not over/under-commented |
| 3 | No Forbidden Content | No dates/authors; no historical notes; no code examples in comments |
| 4 | Docstrings Quality | Match function signatures; parameters documented; return types accurate |
| 5 | Actuality | Comments match code behavior; no stale references; examples runnable |
| 6 | Legacy Cleanup | No TODO without context; no commented-out code; no deprecated notes |
| 序号 | 类别 | 检查内容 |
|---|---|---|
| 1 | WHY而非WHAT | 注释解释的是设计原理,而非显而易见的代码行为;不重复代码内容 |
| 2 | 密度(15-20%) | 注释与代码的比例在范围内;注释过多或过少都不行 |
| 3 | 无禁用内容 | 无日期/作者信息;无历史记录;注释中无代码示例 |
| 4 | 文档字符串质量 | 与函数签名匹配;参数已文档化;返回类型准确 |
| 5 | 时效性 | 注释与代码行为一致;无过时引用;示例可运行 |
| 6 | 遗留内容清理 | 无无上下文的TODO;无被注释掉的代码;无已弃用说明 |
Output Format
输出格式
markdown
undefinedmarkdown
undefinedCode Comments Audit Report - [DATE]
代码注释审计报告 - [日期]
Compliance Score
合规分数
| Category | Score | Issues |
|---|---|---|
| WHY not WHAT | X/10 | N obvious comments |
| Density (15-20%) | X/10 | X% actual (target: 15-20%) |
| No Forbidden Content | X/10 | N forbidden items |
| Docstrings Quality | X/10 | N mismatches |
| Actuality | X/10 | N stale comments |
| Legacy Cleanup | X/10 | N legacy items |
| Overall | X/10 |
| 类别 | 分数 | 问题数 |
|---|---|---|
| WHY而非WHAT | X/10 | N条显而易见的注释 |
| 密度(15-20%) | X/10 | 实际比例X%(目标:15-20%) |
| 无禁用内容 | X/10 | N项禁用内容 |
| 文档字符串质量 | X/10 | N处不匹配 |
| 时效性 | X/10 | N条过时注释 |
| 遗留内容清理 | X/10 | N项遗留内容 |
| 总体 | X/10 |
Critical Findings
关键问题发现
- [Category] - Issue description. Action: Fix suggestion.
path/file:line
- [类别] - 问题描述。操作建议: 修复建议。
路径/文件:行号
Recommended Actions
推荐操作
| Priority | Action | Location | Category |
|---|---|---|---|
| High | Remove author name | src/X:45 | Forbidden |
| Medium | Update stale docstring | lib/Y:120 | Actuality |
undefined| 优先级 | 操作 | 位置 | 类别 |
|---|---|---|---|
| 高 | 移除作者姓名 | src/X:45 | 禁用内容 |
| 中 | 更新过时的文档字符串 | lib/Y:120 | 时效性 |
undefinedScoring Algorithm
评分算法
See for unified formula and score interpretation.
shared/references/audit_scoring.mdSeverity mapping:
| Issue Type | Severity |
|---|---|
| Author names, dates in comments | CRITICAL |
| Commented-out code blocks | HIGH |
| Stale/outdated comments | HIGH |
| Obvious WHAT comments | MEDIUM |
| Density deviation >5% | MEDIUM |
| Minor density deviation | LOW |
统一公式和分数解释请参见。
shared/references/audit_scoring.md严重程度映射:
| 问题类型 | 严重程度 |
|---|---|
| 注释中的作者姓名、日期 | 严重 |
| 被注释掉的代码块 | 高 |
| 过时注释 | 高 |
| 显而易见的WHAT注释 | 中 |
| 密度偏差>5% | 中 |
| 轻微密度偏差 | 低 |
Reference Files
参考文件
- Comment rules and patterns: references/comments_rules.md
- 注释规则和模式:references/comments_rules.md
Critical Notes
重要说明
- Fix code, not rules: NEVER modify rules files (*_rules.md, *_standards.md) to make violations pass. Always fix the code instead.
- Code is truth: When comment contradicts code, flag comment for update
- WHY > WHAT: Comments explaining obvious behavior should be removed
- Task IDs OK: Task/Story IDs in comments help with code traceability
- Universal: Works with any language; detect comment syntax automatically
- Based on: Claude Code comment-analyzer agent patterns
Version: 3.0.0
Last Updated: 2025-12-23
- 修复代码,而非规则: 绝不要修改规则文件(_rules.md、_standards.md)来让违规项通过。始终修复代码。
- 代码即事实: 当注释与代码矛盾时,标记注释需要更新
- WHY > WHAT: 解释显而易见行为的注释应被移除
- 任务ID允许: 注释中的任务/需求ID有助于代码可追溯性
- 通用性: 适用于任何语言;自动检测注释语法
- 基于: Claude Code comment-analyzer agent模式
版本: 3.0.0
最后更新: 2025-12-23