死代码审计

Universal

ln-626-dead-code-auditor

by levnikolaevich

审计项目里的不可达代码、未使用导入/变量/函数、注释掉的旧实现与兼容性 shim,结合上下文排除误报,输出问题清单、Markdown 报告和合规评分。

帮你快速揪出不可达代码、未使用导入和兼容性补丁,特别适合给遗留项目做瘦身与风险排查。

405编码与调试未扫描2026年3月5日

安装

claude skill add --url github.com/levnikolaevich/claude-code-skills/tree/master/ln-626-dead-code-auditor

文档

Paths: File paths (shared/, references/, ../ln-*) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root.

Dead Code Auditor (L3 Worker)

Specialized worker auditing unused and unreachable code.

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)

Inputs (from Coordinator)

MANDATORY READ: Load shared/references/task_delegation_pattern.md#audit-coordinator--worker-contract for contextStore structure.

Receives contextStore with tech stack, codebase root, output_dir.

Workflow

MANDATORY READ: Load shared/references/two_layer_detection.md for detection methodology.

  1. Parse context + output_dir
  2. Run dead code detection (Layer 1: linters, grep)
  3. Analyze context per candidate (Layer 2):
    • Unused functions: used via dynamic import/reflection? Exported in public API? Used in other packages (monorepo)?
    • Commented code: TODO with context or algorithm explanation → FP. Truly dead code block → confirmed
    • Legacy shims: read git blame — age? Is there an issue/PR tracking removal?
  4. Collect confirmed findings
  5. Calculate score
  6. Write Report: Build full markdown report in memory per shared/templates/audit_worker_report_template.md, write to {output_dir}/626-dead-code.md in single Write call
  7. Return Summary: Return minimal summary to coordinator

Audit Rules

MANDATORY READ: Load shared/references/clean_code_checklist.md for universal dead code patterns and severity definitions.

1. Unreachable Code

Detection:

  • Linter rules: no-unreachable (ESLint)
  • Check code after return, throw, break

Severity: MEDIUM

2. Unused Imports/Variables/Functions

Detection:

  • ESLint: no-unused-vars
  • TypeScript: noUnusedLocals, noUnusedParameters
  • Python: flake8 with F401, F841

Severity:

  • MEDIUM: Unused functions (dead weight)
  • LOW: Unused imports (cleanup needed)

3. Commented-Out Code

Detection:

  • Grep for //.*{ or /*.*function patterns
  • Large comment blocks (>10 lines) with code syntax

Severity: LOW

Recommendation: Delete (git preserves history)

4. Legacy Code & Backward Compatibility

What: Backward compatibility shims, deprecated patterns, old code that should be removed

Detection:

  • Renamed variables/functions with old aliases:
    • Pattern: const oldName = newName or export { newModule as oldModule }
    • Pattern: function oldFunc() { return newFunc(); } (wrapper for backward compatibility)
  • Deprecated exports/re-exports:
    • Grep for // DEPRECATED, @deprecated JSDoc tags
    • Pattern: export.*as.*old.* or export.*legacy.*
  • Conditional code for old versions:
    • Pattern: if.*legacy.* or if.*old.*version.* or isOldVersion ? oldFunc() : newFunc()
  • Migration shims and adapters:
    • Pattern: migrate.*, Legacy.*Adapter, .*Shim, .*Compat
  • Comment markers:
    • Grep for // backward compatibility, // legacy support, // TODO: remove in v
    • Grep for // old implementation, // deprecated, // kept for backward

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

Scoring Algorithm

MANDATORY READ: Load shared/references/audit_scoring.md for unified scoring formula.

Output Format

MANDATORY READ: Load shared/templates/audit_worker_report_template.md for file format.

Write report to {output_dir}/626-dead-code.md with category: "Dead Code" and checks: unreachable_code, unused_exports, commented_code, legacy_shims.

Return summary to coordinator:

code
Report written: docs/project/.audit/ln-620/{YYYY-MM-DD}/626-dead-code.md
Score: X.X/10 | Issues: N (C:N H:N M:N L:N)

Reference Files

  • Worker report template: shared/templates/audit_worker_report_template.md
  • Clean code checklist: shared/references/clean_code_checklist.md
  • Audit scoring formula: shared/references/audit_scoring.md
  • Audit output schema: shared/references/audit_output_schema.md

Critical Rules

  • Do not auto-fix: Report only, never delete code
  • Age-aware severity: Legacy shims >6 months = MEDIUM, <3 months = LOW
  • Effort realism: S = <1h, M = 1-4h, L = >4h
  • Exclusions: Skip generated code, vendor, migrations, test fixtures
  • Git-aware: Recommend deletion confidently -- git history preserves old code

Definition of Done

  • contextStore parsed (including output_dir)
  • All 4 checks completed (unreachable code, unused imports/vars/functions, commented-out code, legacy shims)
  • Clean code checklist loaded from shared/references/clean_code_checklist.md
  • Findings collected with severity, location, effort, recommendation
  • Score calculated per shared/references/audit_scoring.md
  • Report written to {output_dir}/626-dead-code.md (atomic single Write call)
  • Summary returned to coordinator

Version: 3.0.0 Last Updated: 2025-12-23

相关 Skills

网页构建器

by anthropics

Universal
热门

面向复杂 claude.ai HTML artifact 开发,快速初始化 React + Tailwind CSS + shadcn/ui 项目并打包为单文件 HTML,适合需要状态管理、路由或多组件交互的页面。

在 claude.ai 里做复杂网页 Artifact 很省心,多组件、状态和路由都能顺手搭起来,React、Tailwind 与 shadcn/ui 组合效率高、成品也更精致。

编码与调试
未扫描119.1k

前端设计

by anthropics

Universal
热门

面向组件、页面、海报和 Web 应用开发,按鲜明视觉方向生成可直接落地的前端代码与高质感 UI,适合做 landing page、Dashboard 或美化现有界面,避开千篇一律的 AI 审美。

想把页面做得既能上线又有设计感,就用前端设计:组件到整站都能产出,难得的是能避开千篇一律的 AI 味。

编码与调试
未扫描119.1k

网页应用测试

by anthropics

Universal
热门

用 Playwright 为本地 Web 应用编写自动化测试,支持启动开发服务器、校验前端交互、排查 UI 异常、抓取截图与浏览器日志,适合调试动态页面和回归验证。

借助 Playwright 一站式验证本地 Web 应用前端功能,调 UI 时还能同步查看日志和截图,定位问题更快。

编码与调试
未扫描119.1k

相关 MCP 服务

GitHub

编辑精选

by GitHub

热门

GitHub 是 MCP 官方参考服务器,让 Claude 直接读写你的代码仓库和 Issues。

这个参考服务器解决了开发者想让 AI 安全访问 GitHub 数据的问题,适合需要自动化代码审查或 Issue 管理的团队。但注意它只是参考实现,生产环境得自己加固安全。

编码与调试
83.9k

by Context7

热门

Context7 是实时拉取最新文档和代码示例的智能助手,让你告别过时资料。

它能解决开发者查找文档时信息滞后的问题,特别适合快速上手新库或跟进更新。不过,依赖外部源可能导致偶尔的数据延迟,建议结合官方文档使用。

编码与调试
52.9k

by tldraw

热门

tldraw 是让 AI 助手直接在无限画布上绘图和协作的 MCP 服务器。

这解决了 AI 只能输出文本、无法视觉化协作的痛点——想象让 Claude 帮你画流程图或白板讨论。最适合需要快速原型设计或头脑风暴的开发者。不过,目前它只是个基础连接器,你得自己搭建画布应用才能发挥全部潜力。

编码与调试
46.4k

评论