prune-dead-code

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Prune Dead Code

清理死代码

Treat every declaration as live until you have proven it safe to remove. Find candidates in four categories, verify each one across the whole repository, and report them all for approval before editing.
在证明某个声明可安全移除之前,一律将其视为活跃代码。从四类候选代码中筛选,在整个仓库中逐一验证,在编辑前将所有发现上报以待批准。

Categories

分类

  1. Confirmed dead: symbols, constants, tokens, or barrel re-exports with zero references.
  2. Dedupe: the same constant, string, or type literal declared verbatim in two or more places.
  3. Drift: a magic literal that duplicates an existing named constant.
  4. Arbitrary limits: caps, thresholds, or timeouts guarding against situations users cannot reach. Quantify the real limit before recommending removal.
  1. 已确认死代码:无任何引用的符号、常量、令牌或桶式导出(barrel re-exports)。
  2. 重复代码去重:在两个或多个位置完全相同的常量、字符串或类型字面量声明。
  3. 代码漂移:与现有命名常量重复的魔法字面量。
  4. 任意限制:针对用户无法触及的场景设置的上限、阈值或超时。在建议移除前需量化实际限制范围。

Workflow

工作流程

  1. Search each category across the whole repository, code and tests alike.
  2. Verify every candidate's usage before judging it; one missed reference makes the verdict wrong.
  3. Classify each candidate as safe to remove or arbitrary but intentional.
  4. Report the table below.
  5. Ask which findings to apply before editing.
  6. Apply approved changes and update affected tests.
  7. Run typecheck, lint, and tests; fix anything the changes broke.
  1. 在整个仓库(包括代码和测试用例)中搜索每一类候选代码。
  2. 在判定前验证每个候选代码的使用情况;遗漏一处引用就会导致判定错误。
  3. 将每个候选代码分类为可安全移除,或属于有意设置的任意限制。
  4. 提交下方表格形式的报告。
  5. 在编辑前询问需应用哪些发现。
  6. 应用已批准的变更,并更新受影响的测试用例。
  7. 运行类型检查、代码扫描和测试;修复变更导致的所有问题。

Required Output

要求输出

Use exactly these columns:
markdown
| Item | Location | Notes |
|------|----------|-------|
| `<symbol>` | `path:line` | Zero references repo-wide (verified). Confirmed dead. |
| `<constant>` | `pathA:line`, `pathB:line` | Identical declaration in 2 files. Dedupe into one shared constant. |
| literal `<value>` | `path:line` | Duplicates `<NAMED_CONSTANT>`; reference the constant to avoid drift. |
| `<CAP>` | `path:line` | Threshold unreachable in practice (state the real limit). Safe to remove. |
  • Item: Exact declaration in backticks, or a short phrase for inline literals.
  • Location:
    path:line
    ; include every dedupe and drift location.
  • Notes: In one sentence, identify the item, confirm usage, and give the verdict.
请严格使用以下列:
markdown
| Item | Location | Notes |
|------|----------|-------|
| `<symbol>` | `path:line` | Zero references repo-wide (verified). Confirmed dead. |
| `<constant>` | `pathA:line`, `pathB:line` | Identical declaration in 2 files. Dedupe into one shared constant. |
| literal `<value>` | `path:line` | Duplicates `<NAMED_CONSTANT>`; reference the constant to avoid drift. |
| `<CAP>` | `path:line` | Threshold unreachable in practice (state the real limit). Safe to remove. |
  • Item:使用反引号包裹的精确声明,或内联字面量的简短描述。
  • Location
    path:line
    格式;包含所有重复代码和代码漂移的位置。
  • Notes:用一句话说明该项内容、确认使用情况并给出判定结果。

Rules

规则

When in doubt, it stays live — remove only what you have proven dead.
  • A symbol used only in its own file may be unexported, not deleted; cross-file consumers require it to stay exported.
  • Check tests before removing exports. Keep exports that cover non-trivial logic, or flag the trade-off.
  • Keep intentional tuning values — animation timings, debounce intervals, sizes, minimums — and report them as arbitrary but intentional.
  • Keep validation and guards that prevent crashes on corrupt or missing data.
  • Treat uncertain dynamic access, reflection, constructed imports, public APIs, and framework entry points as live.
存疑时,一律视为活跃代码——仅移除已证明是死代码的内容。
  • 仅在自身文件中使用的符号可改为非导出,但不可删除;跨文件使用的符号需保持导出状态。
  • 移除导出前检查测试用例。保留覆盖非琐碎逻辑的导出,或标注相关取舍。
  • 保留有意设置的调优值——如动画时长、防抖间隔、尺寸、最小值等——并将其归类为有意设置的任意限制。
  • 保留防止因数据损坏或缺失导致崩溃的验证和防护代码。
  • 将不确定的动态访问、反射、构造导入、公共API和框架入口点视为活跃代码。