ln-626-dead-code-auditor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDead Code Auditor (L3 Worker)
死代码审计器(L3 Worker)
Specialized worker auditing unused and unreachable code.
专门用于审计未使用和不可达代码的Worker。
Purpose & Scope
目标与范围
- Worker in ln-620 coordinator pipeline
- Audit dead code (Category 9: Low Priority)
- Find unused imports, variables, functions, commented-out code
- Calculate compliance score (X/10)
- ln-620协调器流水线中的Worker
- 审计死代码(类别9:低优先级)
- 查找未使用的导入、变量、函数和被注释的代码
- 计算合规性分数(X/10)
Inputs (from Coordinator)
输入(来自协调器)
Receives with tech stack, codebase root.
contextStore接收包含技术栈和代码库根目录的。
contextStoreWorkflow
工作流程
- Parse context
- Run dead code detection (linters, grep)
- Collect findings
- Calculate score
- Return JSON
- 解析上下文
- 运行死代码检测(使用代码检查器、grep工具)
- 收集检测结果
- 计算分数
- 返回JSON格式结果
Audit Rules
审计规则
1. Unreachable Code
1. 不可达代码
Detection:
- Linter rules: (ESLint)
no-unreachable - Check code after ,
return,throwbreak
Severity: MEDIUM
检测方式:
- 代码检查器规则:(ESLint)
no-unreachable - 检查、
return、throw语句之后的代码break
严重程度:中等
2. Unused Imports/Variables/Functions
2. 未使用的导入/变量/函数
Detection:
- ESLint:
no-unused-vars - TypeScript: ,
noUnusedLocalsnoUnusedParameters - Python: with
flake8,F401F841
Severity:
- MEDIUM: Unused functions (dead weight)
- LOW: Unused imports (cleanup needed)
检测方式:
- ESLint:
no-unused-vars - TypeScript:、
noUnusedLocalsnoUnusedParameters - Python:带有、
F401规则的F841flake8
严重程度:
- 中等:未使用的函数(冗余代码)
- 低:未使用的导入(需要清理)
3. Commented-Out Code
3. 被注释的代码
Detection:
- Grep for or
//.*{patterns/*.*function - Large comment blocks (>10 lines) with code syntax
Severity: LOW
Recommendation: Delete (git preserves history)
检测方式:
- 使用grep匹配或
//.*{模式/*.*function - 包含代码语法的大注释块(超过10行)
严重程度:低
建议: 删除(git会保留历史记录)
4. Legacy Code & Backward Compatibility
4. 遗留代码与向后兼容
What: Backward compatibility shims, deprecated patterns, old code that should be removed
Detection:
- Renamed variables/functions with old aliases:
- Pattern: or
const oldName = newNameexport { newModule as oldModule } - Pattern: (wrapper for backward compatibility)
function oldFunc() { return newFunc(); }
- Pattern:
- Deprecated exports/re-exports:
- Grep for ,
// DEPRECATEDJSDoc tags@deprecated - Pattern: or
export.*as.*old.*export.*legacy.*
- Grep for
- Conditional code for old versions:
- Pattern: or
if.*legacy.*orif.*old.*version.*isOldVersion ? oldFunc() : newFunc()
- Pattern:
- Migration shims and adapters:
- Pattern: ,
migrate.*,Legacy.*Adapter,.*Shim.*Compat
- Pattern:
- Comment markers:
- Grep for ,
// backward compatibility,// legacy support// TODO: remove in v - Grep for ,
// old implementation,// deprecated// kept for backward
- Grep for
Severity:
- HIGH: Backward compatibility shims in critical paths (auth, payment, core features)
- MEDIUM: Deprecated exports still in use, migration code from >6 months ago
- LOW: Recent migration code (<3 months), planned deprecation with clear removal timeline
Recommendation:
- Remove backward compatibility shims - breaking changes are acceptable when properly versioned
- Delete old implementations - keep only the correct/new version
- Remove deprecated exports - update consumers to use new API
- Delete migration code after grace period (3-6 months)
- Clean legacy support comments - git history preserves old implementations
Effort:
- S: Remove simple aliases, delete deprecated exports
- M: Refactor code using old APIs to new APIs
- L: Remove complex backward compatibility layer affecting multiple modules
说明: 向后兼容垫片、废弃模式以及应被移除的旧代码
检测方式:
- 带有旧别名的重命名变量/函数:
- 模式:或
const oldName = newNameexport { newModule as oldModule } - 模式:(用于向后兼容的包装函数)
function oldFunc() { return newFunc(); }
- 模式:
- 废弃的导出/重导出:
- 使用grep匹配、
// DEPRECATEDJSDoc标签@deprecated - 模式:或
export.*as.*old.*export.*legacy.*
- 使用grep匹配
- 针对旧版本的条件代码:
- 模式:或
if.*legacy.*或if.*old.*version.*isOldVersion ? oldFunc() : newFunc()
- 模式:
- 迁移垫片与适配器:
- 模式:、
migrate.*、Legacy.*Adapter、.*Shim.*Compat
- 模式:
- 注释标记:
- 使用grep匹配、
// backward compatibility、// legacy support// TODO: remove in v - 使用grep匹配、
// old implementation、// deprecated// kept for backward
- 使用grep匹配
严重程度:
- 高:关键路径(认证、支付、核心功能)中的向后兼容垫片
- 中等:仍在使用的废弃导出、超过6个月的迁移代码
- 低:近期迁移代码(少于3个月)、有明确移除时间线的计划中废弃项
建议:
- 移除向后兼容垫片——在版本管理规范的情况下,破坏性变更可被接受
- 删除旧实现——仅保留正确/新版本的代码
- 移除废弃的导出——更新消费者以使用新API
- 宽限期(3-6个月)后删除迁移代码
- 清理遗留支持注释——git历史记录会保留旧实现
工作量:
- 小:移除简单别名,删除废弃的导出
- 中:重构使用旧API的代码以适配新API
- 大:移除影响多个模块的复杂向后兼容层
Scoring Algorithm
评分算法
See for unified formula and score interpretation.
shared/references/audit_scoring.md统一的计算公式和分数说明请参考。
shared/references/audit_scoring.mdOutput Format
输出格式
json
{
"category": "Dead Code",
"score": 6,
"total_issues": 12,
"critical": 0,
"high": 2,
"medium": 3,
"low": 7,
"checks": [
{"id": "unreachable_code", "name": "Unreachable Code", "status": "passed", "details": "No unreachable code detected"},
{"id": "unused_exports", "name": "Unused Exports", "status": "failed", "details": "3 unused functions found"},
{"id": "commented_code", "name": "Commented Code", "status": "warning", "details": "7 blocks of commented code"},
{"id": "legacy_shims", "name": "Legacy Shims", "status": "failed", "details": "2 backward compatibility shims"}
],
"findings": [
{
"severity": "MEDIUM",
"location": "src/utils/helpers.ts:45",
"issue": "Function 'formatDate' is never used",
"principle": "Code Maintainability / Clean Code",
"recommendation": "Remove unused function or export if needed elsewhere",
"effort": "S"
},
{
"severity": "HIGH",
"location": "src/api/v1/auth.ts:12-15",
"issue": "Backward compatibility shim for old password validation (6+ months old)",
"principle": "No Legacy Code / Clean Architecture",
"recommendation": "Remove old password validation, keep only new implementation. Update API version if breaking.",
"effort": "M"
}
]
}json
{
"category": "Dead Code",
"score": 6,
"total_issues": 12,
"critical": 0,
"high": 2,
"medium": 3,
"low": 7,
"checks": [
{"id": "unreachable_code", "name": "Unreachable Code", "status": "passed", "details": "No unreachable code detected"},
{"id": "unused_exports", "name": "Unused Exports", "status": "failed", "details": "3 unused functions found"},
{"id": "commented_code", "name": "Commented Code", "status": "warning", "details": "7 blocks of commented code"},
{"id": "legacy_shims", "name": "Legacy Shims", "status": "failed", "details": "2 backward compatibility shims"}
],
"findings": [
{
"severity": "MEDIUM",
"location": "src/utils/helpers.ts:45",
"issue": "Function 'formatDate' is never used",
"principle": "Code Maintainability / Clean Code",
"recommendation": "Remove unused function or export if needed elsewhere",
"effort": "S"
},
{
"severity": "HIGH",
"location": "src/api/v1/auth.ts:12-15",
"issue": "Backward compatibility shim for old password validation (6+ months old)",
"principle": "No Legacy Code / Clean Architecture",
"recommendation": "Remove old password validation, keep only new implementation. Update API version if breaking.",
"effort": "M"
}
]
}Reference Files
参考文件
- Audit scoring formula:
shared/references/audit_scoring.md - Audit output schema:
shared/references/audit_output_schema.md
Version: 3.0.0
Last Updated: 2025-12-23
- 审计评分公式:
shared/references/audit_scoring.md - 审计输出 schema:
shared/references/audit_output_schema.md
版本: 3.0.0
最后更新时间: 2025-12-23