dead-code-check
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDead Code Detection
死代码检测
Overview
概述
Dead code detection identifies code that exists in your codebase but is never called, imported, or used. This is a critical signal for incomplete feature integration: if you've written a function but nothing calls it, the feature isn't wired up.
In loom plan verification, dead code checks serve two purposes:
- Wiring verification: Catch features that were implemented but never integrated
- Code quality: Identify cleanup opportunities and reduce maintenance burden
Dead code detection is especially valuable in integration-verify stages, where it acts as a final check that all implemented code is actually connected to the application.
死代码检测用于识别代码库中存在但从未被调用、导入或使用的代码。这是功能集成不完整的关键信号:如果你编写了一个函数但没有任何代码调用它,说明该功能未完成集成。
在Loom计划验证中,死代码检查有两个作用:
- 集成验证:捕获已实现但未集成的功能
- 代码质量:识别需要清理的代码,降低维护负担
死代码检测在集成验证阶段尤为重要,它可作为最终检查环节,确保所有已实现的代码都已接入应用。
When to Use
使用场景
- integration-verify stages: Final quality gate to catch orphaned code from all implementation stages
- Per-stage acceptance criteria: Immediate feedback during implementation
- Code cleanup: After refactoring or feature removal
- Wiring validation: Combine with wiring checks to verify feature integration
If dead code exists after implementation, it typically means:
- Feature wasn't wired into the application (CLI command not registered, route not mounted, etc.)
- Test code that isn't being run
- Leftover code from refactoring
- Incomplete implementation
- 集成验证阶段:作为最终质量关卡,捕获所有实现阶段产生的孤立代码
- 阶段验收标准:在实现过程中提供即时反馈
- 代码清理:重构或移除功能后使用
- 集成验证:结合集成检查,验证功能是否正确接入
如果实现后仍存在死代码,通常意味着:
- 功能未接入应用(CLI命令未注册、路由未挂载等)
- 测试代码未被执行
- 重构遗留的代码
- 未完成的实现
Language-Specific Configurations
各语言专属配置
Rust
Rust
Rust has built-in dead code detection via the compiler and clippy.
Recommended Approach: Use clippy with all warnings as errors
bash
cargo clippy -- -D warningsThis catches dead code plus many other issues (unused imports, variables, etc.).
Dead-Code-Specific Check:
bash
RUSTFLAGS="-D dead_code" cargo build 2>&1Or target just dead code warnings:
bash
cargo clippy -- -D dead_codeFail Patterns:
warning: unuseddead_codeunused importunused variablenever usednever constructed
Ignore Patterns:
- Code with attribute (intentional)
#[allow(dead_code)] - Test modules ()
#[cfg(test)] - Main entry points ()
fn main() - Public API items intended for external consumers
- Items behind feature gates that aren't enabled
YAML Template for Loom Plans:
yaml
undefinedRust通过编译器和clippy内置了死代码检测功能。
推荐方案:使用clippy并将所有警告设为错误
bash
cargo clippy -- -D warnings该命令可捕获死代码及其他诸多问题(未使用的导入、变量等)。
仅检查死代码的命令:
bash
RUSTFLAGS="-D dead_code" cargo build 2>&1或者仅针对死代码警告:
bash
cargo clippy -- -D dead_code失败匹配规则:
warning: unuseddead_codeunused importunused variablenever usednever constructed
忽略规则:
- 带有属性的代码(有意保留)
#[allow(dead_code)] - 测试模块()
#[cfg(test)] - 主入口函数()
fn main() - 供外部消费者使用的公共API项
- 未启用的功能门控后的代码
Loom计划的YAML模板:
yaml
undefinedIn acceptance criteria (recommended - catches more than just dead code)
在验收标准中(推荐,可捕获除死代码外的更多问题)
acceptance:
- "cargo clippy -- -D warnings"
acceptance:
- "cargo clippy -- -D warnings"
In truths (more specific dead code check)
在truths中(更针对性的死代码检查)
truths:
- "RUSTFLAGS="-D dead_code" cargo build 2>&1 | grep -v 'Compiling' | grep -v 'Finished' | grep -q '^$'"
truths:
- "RUSTFLAGS="-D dead_code" cargo build 2>&1 | grep -v 'Compiling' | grep -v 'Finished' | grep -q '^$'"
Alternative: Check that clippy reports zero dead code warnings
替代方案:检查clippy是否未报告任何死代码警告
truths:
- "! cargo clippy -- -D dead_code 2>&1 | grep -q 'warning:'"
**Working Directory Consideration:**
Rust checks must run where `Cargo.toml` exists. If your project structure is:
```text
.worktrees/my-stage/
└── loom/
└── Cargo.tomlSet in your stage configuration.
working_dir: "loom"truths:
- "! cargo clippy -- -D dead_code 2>&1 | grep -q 'warning:'"
**工作目录注意事项:**
Rust检查必须在存在`Cargo.toml`的目录下运行。如果你的项目结构如下:
```text
.worktrees/my-stage/
└── loom/
└── Cargo.toml请在阶段配置中设置。
working_dir: "loom"TypeScript
TypeScript
TypeScript dead code detection uses ts-prune, which finds unused exports.
Installation:
bash
npm install --save-dev ts-pruneTypeScript的死代码检测使用ts-prune,它可发现未使用的导出项。
安装:
bash
npm install --save-dev ts-pruneor
或
bun add --dev ts-prune
**Command:**
```bash
npx ts-prune --errorbun add --dev ts-prune
**命令:**
```bash
npx ts-prune --erroror
或
bunx ts-prune --error
The `--error` flag makes ts-prune exit with non-zero status if unused exports are found.
**Fail Patterns:**
- `used in module but not exported`
- `unused export`
- Files with unused exports reported
**Ignore Patterns:**
- `index.ts` files that re-export (barrel files)
- Type-only exports used for type checking
- Declaration files (`.d.ts`)
- Public API exports intended for library consumers
- Default exports in entry points
**Configuration File (`.tsprunerc`):**
```json
{
"ignore": "index.ts|types.d.ts"
}YAML Template for Loom Plans:
yaml
undefinedbunx ts-prune --error
`--error`参数会让ts-prune在发现未使用导出项时返回非零状态码。
**失败匹配规则:**
- `used in module but not exported`
- `unused export`
- 报告存在未使用导出项的文件
**忽略规则:**
- 用于重新导出的`index.ts`文件(桶文件)
- 仅用于类型检查的类型导出项
- 声明文件(`.d.ts`)
- 供库消费者使用的公共API导出项
- 入口文件中的默认导出
**配置文件(`.tsprunerc`):**
```json
{
"ignore": "index.ts|types.d.ts"
}Loom计划的YAML模板:
yaml
undefinedIn acceptance criteria
在验收标准中
acceptance:
- "bunx ts-prune --error"
acceptance:
- "bunx ts-prune --error"
In truths (verify zero unused exports)
在truths中(验证无未使用导出项)
truths:
- "bunx ts-prune | wc -l | grep -q '^0$'"
truths:
- "bunx ts-prune | wc -l | grep -q '^0$'"
Alternative: Explicitly check for no unused exports
替代方案:检查是否存在特定问题
truths:
- "! bunx ts-prune | grep -q 'used in module'"
**Working Directory:**
Run where `package.json` and `tsconfig.json` exist.
---truths:
- "! bunx ts-prune | grep -q 'used in module'"
**工作目录:**
在存在`package.json`和`tsconfig.json`的目录下运行。
---Python
Python
Python dead code detection uses vulture, which finds unused code including functions, classes, variables, and imports.
Installation:
bash
pip install vulturePython的死代码检测使用vulture,它可发现未使用的函数、类、变量和导入项。
安装:
bash
pip install vultureor
或
uv add --dev vulture
**Command:**
```bash
vulture src/ --min-confidence 80The flag (0-100) controls false positive rate. Higher values mean fewer false positives but might miss some dead code.
--min-confidenceFail Patterns:
unused functionunused classunused variableunused importunreachable code
Ignore Patterns:
- files
__init__.py - definitions (explicit public API)
__all__ - Magic methods (,
__str__,__repr__, etc.)__eq__ - Test files and fixtures (often use dynamic discovery)
- Setup.py and configuration files
Configuration File ():
pyproject.tomltoml
[tool.vulture]
min_confidence = 80
paths = ["src", "tests"]
ignore_names = ["setUp", "tearDown", "test_*"]YAML Template for Loom Plans:
yaml
undefineduv add --dev vulture
**命令:**
```bash
vulture src/ --min-confidence 80--min-confidence失败匹配规则:
unused functionunused classunused variableunused importunreachable code
忽略规则:
- 文件
__init__.py - 定义(显式声明的公共API)
__all__ - 魔术方法(、
__str__、__repr__等)__eq__ - 测试文件和测试夹具(通常使用动态发现机制)
- Setup.py及配置文件
配置文件():
pyproject.tomltoml
[tool.vulture]
min_confidence = 80
paths = ["src", "tests"]
ignore_names = ["setUp", "tearDown", "test_*"]Loom计划的YAML模板:
yaml
undefinedIn acceptance criteria
在验收标准中
acceptance:
- "vulture src/ --min-confidence 80"
acceptance:
- "vulture src/ --min-confidence 80"
In truths (verify zero issues)
在truths中(验证无问题)
truths:
- "vulture src/ --min-confidence 80 | wc -l | grep -q '^0$'"
truths:
- "vulture src/ --min-confidence 80 | wc -l | grep -q '^0$'"
Alternative: Check for specific patterns
替代方案:检查特定问题
truths:
- "! vulture src/ --min-confidence 80 | grep -q 'unused function'"
- "! vulture src/ --min-confidence 80 | grep -q 'unused import'"
**Working Directory:**
Run where your Python source code is (usually project root or where `pyproject.toml` exists).
---truths:
- "! vulture src/ --min-confidence 80 | grep -q 'unused function'"
- "! vulture src/ --min-confidence 80 | grep -q 'unused import'"
**工作目录:**
在Python源代码所在目录运行(通常是项目根目录或`pyproject.toml`所在目录)。
---Go
Go
Go dead code detection uses staticcheck, a comprehensive static analysis tool.
Installation:
bash
go install honnef.co/go/tools/cmd/staticcheck@latestCommand:
bash
staticcheck ./...Relevant Checks:
- - unused code (function, type, const, var)
U1000 - - unused field
U1001
Fail Patterns:
is unusedfield .* is unusedfunc .* is unused- check code
U1000 - check code
U1001
Ignore Patterns:
- Exported symbols in library packages (public API)
- Interface method implementations (required by interface even if not directly called)
- Functions assigned to variables for use via reflection
- Code behind build tags not currently enabled
Configuration File ():
.staticcheck.conftext
checks = ["all", "-ST1000"]YAML Template for Loom Plans:
yaml
undefinedGo的死代码检测使用staticcheck,一款全面的静态分析工具。
安装:
bash
go install honnef.co/go/tools/cmd/staticcheck@latest命令:
bash
staticcheck ./...相关检查项:
- - 未使用的代码(函数、类型、常量、变量)
U1000 - - 未使用的字段
U1001
失败匹配规则:
is unusedfield .* is unusedfunc .* is unused- 检查码
U1000 - 检查码
U1001
忽略规则:
- 库包中的导出符号(公共API)
- 接口方法实现(即使未直接调用,接口也要求必须实现)
- 赋值给变量用于反射调用的函数
- 当前未启用的构建标签后的代码
配置文件():
.staticcheck.conftext
checks = ["all", "-ST1000"]Loom计划的YAML模板:
yaml
undefinedIn acceptance criteria
在验收标准中
acceptance:
- "staticcheck ./..."
acceptance:
- "staticcheck ./..."
In truths (verify no unused code)
在truths中(验证无未使用代码)
truths:
- "! staticcheck ./... | grep -q 'U1000'"
- "! staticcheck ./... | grep -q 'is unused'"
truths:
- "! staticcheck ./... | grep -q 'U1000'"
- "! staticcheck ./... | grep -q 'is unused'"
Alternative: Check exit code
替代方案:检查退出码
truths:
- "staticcheck ./... 2>&1 | wc -l | grep -q '^0$'"
**Working Directory:**
Run where `go.mod` exists (usually project root).
---truths:
- "staticcheck ./... 2>&1 | wc -l | grep -q '^0$'"
**工作目录:**
在存在`go.mod`的目录下运行(通常是项目根目录)。
---JavaScript
JavaScript
JavaScript dead code detection uses unimported, which finds unused files and unresolved imports.
Installation:
bash
npm install --save-dev unimportedJavaScript的死代码检测使用unimported,它可发现未使用的文件及未解析的导入项。
安装:
bash
npm install --save-dev unimportedor
或
bun add --dev unimported
**Command:**
```bash
npx unimportedbun add --dev unimported
**命令:**
```bash
npx unimportedor
或
bunx unimported
**Fail Patterns:**
- `unresolved import`
- `unused file`
- Files listed in output
**Ignore Patterns:**
- Config files (`.eslintrc.js`, `jest.config.js`, etc.)
- Entry points (`index.js`, `main.js`)
- Dynamic imports using variables
- Files imported via build tools (Webpack, Vite, etc.)
**Configuration File (`.unimportedrc.json`):**
```json
{
"entry": ["src/index.js", "src/server.js"],
"extensions": [".js", ".jsx"],
"ignorePatterns": ["**/node_modules/**", "**/*.config.js"]
}YAML Template for Loom Plans:
yaml
undefinedbunx unimported
**失败匹配规则:**
- `unresolved import`
- `unused file`
- 输出中列出的文件
**忽略规则:**
- 配置文件(`.eslintrc.js`、`jest.config.js`等)
- 入口文件(`index.js`、`main.js`)
- 使用变量的动态导入
- 通过构建工具(Webpack、Vite等)导入的文件
**配置文件(`.unimportedrc.json`):**
```json
{
"entry": ["src/index.js", "src/server.js"],
"extensions": [".js", ".jsx"],
"ignorePatterns": ["**/node_modules/**", "**/*.config.js"]
}Loom计划的YAML模板:
yaml
undefinedIn acceptance criteria
在验收标准中
acceptance:
- "bunx unimported"
acceptance:
- "bunx unimported"
In truths (verify no unused files)
在truths中(验证无未使用文件)
truths:
- "bunx unimported | wc -l | grep -q '^0$'"
truths:
- "bunx unimported | wc -l | grep -q '^0$'"
Alternative: Check for specific issues
替代方案:检查特定问题
truths:
- "! bunx unimported | grep -q 'unused file'"
- "! bunx unimported | grep -q 'unresolved import'"
**Working Directory:**
Run where `package.json` exists.
---truths:
- "! bunx unimported | grep -q 'unused file'"
- "! bunx unimported | grep -q 'unresolved import'"
**工作目录:**
在存在`package.json`的目录下运行。
---Handling False Positives
处理误报
Dead code detection tools report false positives in these common scenarios:
死代码检测工具在以下常见场景中会产生误报:
1. Entry Points
1. 入口点
Problem: Main functions, CLI handlers, API route handlers — nothing in your code calls them directly, but they're invoked by the runtime/framework.
Solutions:
- Rust: Entry points like are automatically excluded. For CLI subcommands, ensure they're registered in the command enum.
fn main() - TypeScript/JavaScript: Configure entry points in tool config (ts-prune, unimported)
- Python: Use to mark public API, vulture respects it
__all__ - Go: Exported functions in package are excluded
main
问题: 主函数、CLI处理器、API路由处理器等,代码中没有直接调用它们,但会被运行时/框架调用。
解决方案:
- Rust:等入口点会被自动排除。对于CLI子命令,确保它们已在命令枚举中注册。
fn main() - TypeScript/JavaScript:在工具配置中指定入口点(ts-prune、unimported)
- Python:使用标记公共API,vulture会尊重该配置
__all__ - Go:包中的导出函数会被排除
main
2. Test Code
2. 测试代码
Problem: Test functions are called by the test runner, not by application code.
Solutions:
- Rust: Code in modules is automatically excluded
#[cfg(test)] - TypeScript/JavaScript: Exclude test directories in config
- Python: Ignore patterns like ,
test_*,setUptearDown - Go: Test files () are automatically handled
*_test.go
问题: 测试函数由测试运行器调用,而非应用代码。
解决方案:
- Rust:模块中的代码会被自动排除
#[cfg(test)] - TypeScript/JavaScript:在配置中排除测试目录
- Python:忽略、
test_*、setUp等命名模式tearDown - Go:测试文件()会被自动处理
*_test.go
3. Framework Magic
3. 框架魔术特性
Problem: Decorators, derive macros, annotations that use code implicitly.
Examples:
- Rust: uses private fields
#[derive(Serialize)] - Python: ,
@dataclassdecorators@property - TypeScript: Decorators in frameworks like Angular, NestJS
Solutions:
- Use language-specific ignore annotations
- Configure tools to ignore decorated items
- For Rust, use on specific items
#[allow(dead_code)]
问题: 装饰器、派生宏、注解会隐式使用代码。
示例:
- Rust:会使用私有字段
#[derive(Serialize)] - Python:、
@dataclass装饰器@property - TypeScript:Angular、NestJS等框架中的装饰器
解决方案:
- 使用语言专属的忽略注解
- 配置工具忽略带有装饰器的项
- Rust中,对特定项使用
#[allow(dead_code)]
4. Public API / Library Code
4. 公共API / 库代码
Problem: Code exported for external consumers appears unused within the project.
Solutions:
- Rust: Public items () in library crates are excluded by default
pub - TypeScript: Use to ignore library entry points
.tsprunerc - Python: Define to mark public API
__all__ - Go: Exported symbols (capitalized) in library packages are excluded
问题: 供外部消费者使用的代码在项目内部显示为未使用。
解决方案:
- Rust:库 crate 中的公共项()默认会被排除
pub - TypeScript:使用忽略库入口点
.tsprunerc - Python:定义标记公共API
__all__ - Go:库包中的导出符号(首字母大写)会被排除
5. Feature Flags and Conditional Compilation
5. 功能标志与条件编译
Problem: Code behind disabled feature flags or build tags.
Solutions:
- Rust: Enable relevant features when running checks ()
--features=all - Go: Use build tags to include all variants
- Python/TypeScript/JavaScript: Comment or temporarily enable features during checks
问题: 禁用的功能标志或构建标签后的代码。
解决方案:
- Rust:运行检查时启用相关功能()
--features=all - Go:使用构建标签包含所有变体
- Python/TypeScript/JavaScript:检查期间注释或临时启用功能
6. Dynamic Loading and Reflection
6. 动态加载与反射
Problem: Code loaded dynamically or invoked via reflection.
Solutions:
- Document these cases clearly
- Use tool-specific ignore comments
- Consider integration tests that exercise dynamic code paths
问题: 动态加载或通过反射调用的代码。
解决方案:
- 清晰记录这些情况
- 使用工具专属的忽略注释
- 考虑编写集成测试覆盖动态代码路径
Integration with Loom Plans
与Loom计划集成
Placement in Plan Stages
在计划阶段中的位置
Best Practice: integration-verify stage
Dead code checks are most valuable as a final quality gate:
yaml
stages:
- id: integration-verify
name: "Integration Verification"
stage_type: integration-verify
working_dir: "loom"
acceptance:
- "cargo test"
- "cargo clippy -- -D warnings" # Includes dead code check
truths:
- "! cargo clippy -- -D dead_code 2>&1 | grep -q 'warning:'"Per-Stage Checks:
Can also add to individual implementation stages for immediate feedback:
yaml
stages:
- id: implement-auth
name: "Implement Authentication"
stage_type: standard
working_dir: "loom"
acceptance:
- "cargo test auth"
- "cargo clippy --package auth -- -D warnings"最佳实践:集成验证阶段
死代码检查作为最终质量关卡时价值最大:
yaml
stages:
- id: integration-verify
name: "Integration Verification"
stage_type: integration-verify
working_dir: "loom"
acceptance:
- "cargo test"
- "cargo clippy -- -D warnings" # 包含死代码检查
truths:
- "! cargo clippy -- -D dead_code 2>&1 | grep -q 'warning:'"阶段内检查:
也可添加到各个实现阶段,提供即时反馈:
yaml
stages:
- id: implement-auth
name: "Implement Authentication"
stage_type: standard
working_dir: "loom"
acceptance:
- "cargo test auth"
- "cargo clippy --package auth -- -D warnings"Combining with Wiring Checks
与集成检查结合使用
Dead code detection is a strong signal but not definitive proof. Combine with checks:
wiringyaml
stages:
- id: integration-verify
name: "Integration Verification"
stage_type: integration-verify
working_dir: "loom"
acceptance:
- "cargo clippy -- -D warnings"
wiring:
- source: "src/main.rs"
pattern: "Commands::NewCommand"
description: "New command registered in CLI enum"
- source: "src/commands/mod.rs"
pattern: "pub mod new_command"
description: "New command module exported"
truths:
- "loom new-command --help" # Functional verificationThis triple-check approach (dead code + wiring + functional) catches integration issues reliably.
死代码检测是一个强烈的信号,但并非 definitive 的证明。需与检查结合:
wiringyaml
stages:
- id: integration-verify
name: "Integration Verification"
stage_type: integration-verify
working_dir: "loom"
acceptance:
- "cargo clippy -- -D warnings"
wiring:
- source: "src/main.rs"
pattern: "Commands::NewCommand"
description: "New command registered in CLI enum"
- source: "src/commands/mod.rs"
pattern: "pub mod new_command"
description: "New command module exported"
truths:
- "loom new-command --help" # 功能验证这种三重检查方式(死代码检测 + 集成检查 + 功能测试)可可靠地捕获集成问题。
Working Directory and Paths
工作目录与路径
Critical Reminder: The field determines where commands execute.
working_dirExample project structure:
text
.worktrees/my-stage/
├── loom/
│ ├── Cargo.toml <- Build tools expect this directory
│ └── src/
└── CLAUDE.mdCorrect Configuration:
yaml
- id: verify
working_dir: "loom" # Where Cargo.toml exists
acceptance:
- "cargo clippy -- -D warnings"
truths:
- "test -f src/new_feature.rs" # Relative to working_dir (loom/)Wrong Configuration:
yaml
- id: verify
working_dir: "." # Wrong - no Cargo.toml here
acceptance:
- "cargo clippy -- -D warnings" # FAILS: could not find Cargo.tomlPath Resolution Rule: ALL paths in acceptance, truths, artifacts, and wiring are relative to .
working_dir重要提醒: 字段决定命令的执行位置。
working_dir示例项目结构:
text
.worktrees/my-stage/
├── loom/
│ ├── Cargo.toml <- 构建工具期望在此目录
│ └── src/
└── CLAUDE.md正确配置:
yaml
- id: verify
working_dir: "loom" # Cargo.toml所在目录
acceptance:
- "cargo clippy -- -D warnings"
truths:
- "test -f src/new_feature.rs" # 相对于working_dir(loom/)错误配置:
yaml
- id: verify
working_dir: "." # 错误 - 此处无Cargo.toml
acceptance:
- "cargo clippy -- -D warnings" # 失败:找不到Cargo.toml路径解析规则: 验收标准、truths、产物及wiring中的所有路径均相对于。
working_dirYAML Best Practices
YAML最佳实践
Never Use Triple Backticks in YAML Descriptions
切勿在YAML描述中使用三重反引号
Wrong:
yaml
truths:
- description: |
Check for dead code like this:
```
cargo clippy -- -D warnings
```
command: "cargo clippy -- -D warnings"This breaks YAML parsing.
Correct:
yaml
truths:
- "cargo clippy -- -D warnings" # Check for dead codeOr with explicit description:
yaml
truths:
- description: "Check for dead code using clippy with all warnings as errors"
command: "cargo clippy -- -D warnings"错误写法:
yaml
truths:
- description: |
Check for dead code like this:
```
cargo clippy -- -D warnings
```
command: "cargo clippy -- -D warnings"这会破坏YAML解析。
正确写法:
yaml
truths:
- "cargo clippy -- -D warnings" # 检查死代码或带显式描述:
yaml
truths:
- description: "使用clippy将所有警告设为错误,检查死代码"
command: "cargo clippy -- -D warnings"Silent Grep with -q
使用-q参数静默执行grep
When using in truths, use (quiet) flag to suppress output:
grep-qyaml
truths:
- "! cargo clippy -- -D dead_code 2>&1 | grep -q 'warning:'"The negates the result (exit 0 if grep finds nothing).
!在truths中使用时,使用(静默)参数抑制输出:
grep-qyaml
truths:
- "! cargo clippy -- -D dead_code 2>&1 | grep -q 'warning:'"!Exit Code Checks
退出码检查
Tools that exit non-zero on finding issues can be used directly:
yaml
acceptance:
- "cargo clippy -- -D warnings" # Exits non-zero on warnings
- "staticcheck ./..." # Exits non-zero on issues
- "bunx ts-prune --error" # Exits non-zero on unused exports可直接使用发现问题时返回非零状态码的工具:
yaml
acceptance:
- "cargo clippy -- -D warnings" # 出现警告时返回非零
- "staticcheck ./..." # 出现问题时返回非零
- "bunx ts-prune --error" # 发现未使用导出项时返回非零Tool Installation Checklist
工具安装检查清单
Before adding dead code checks to your plan, ensure tools are available:
Rust:
- Built-in: ,
rustccargo - (usually included with rustup)
cargo install clippy
TypeScript:
- or
bun add --dev ts-prunenpm install --save-dev ts-prune
Python:
- or
uv add --dev vulturepip install vulture
Go:
go install honnef.co/go/tools/cmd/staticcheck@latest
JavaScript:
- or
bun add --dev unimportednpm install --save-dev unimported
Add installation steps to your stage or document in project README.
knowledge-bootstrap在将死代码检查添加到计划前,确保工具已可用:
Rust:
- 内置工具:、
rustccargo - (通常随rustup一起安装)
cargo install clippy
TypeScript:
- 或
bun add --dev ts-prunenpm install --save-dev ts-prune
Python:
- 或
uv add --dev vulturepip install vulture
Go:
go install honnef.co/go/tools/cmd/staticcheck@latest
JavaScript:
- 或
bun add --dev unimportednpm install --save-dev unimported
可将安装步骤添加到阶段,或在项目README中说明。
knowledge-bootstrapExamples
示例
Example 1: Rust Project with Comprehensive Checks
示例1:包含全面检查的Rust项目
yaml
stages:
- id: integration-verify
name: "Integration Verification"
stage_type: integration-verify
working_dir: "loom"
acceptance:
- "cargo test"
- "cargo clippy -- -D warnings"
- "cargo build --release"
truths:
- "test -f src/commands/new_feature.rs"
- "! cargo clippy -- -D dead_code 2>&1 | grep -q 'warning:'"
wiring:
- source: "src/main.rs"
pattern: "Commands::NewFeature"
description: "New feature command registered"yaml
stages:
- id: integration-verify
name: "Integration Verification"
stage_type: integration-verify
working_dir: "loom"
acceptance:
- "cargo test"
- "cargo clippy -- -D warnings"
- "cargo build --release"
truths:
- "test -f src/commands/new_feature.rs"
- "! cargo clippy -- -D dead_code 2>&1 | grep -q 'warning:'"
wiring:
- source: "src/main.rs"
pattern: "Commands::NewFeature"
description: "New feature command registered"Example 2: TypeScript API with Dead Export Check
示例2:包含死导出检查的TypeScript API
yaml
stages:
- id: verify-api
name: "Verify API Implementation"
stage_type: integration-verify
working_dir: "api"
acceptance:
- "bun test"
- "bunx ts-prune --error"
- "bun run typecheck"
truths:
- "bunx ts-prune | wc -l | grep -q '^0$'"
- "curl -f http://localhost:3000/api/health"yaml
stages:
- id: verify-api
name: "Verify API Implementation"
stage_type: integration-verify
working_dir: "api"
acceptance:
- "bun test"
- "bunx ts-prune --error"
- "bun run typecheck"
truths:
- "bunx ts-prune | wc -l | grep -q '^0$'"
- "curl -f http://localhost:3000/api/health"Example 3: Python Data Pipeline
示例3:Python数据管道
yaml
stages:
- id: verify-pipeline
name: "Verify Data Pipeline"
stage_type: integration-verify
working_dir: "pipeline"
acceptance:
- "pytest"
- "vulture src/ --min-confidence 80"
- "mypy src/"
truths:
- "! vulture src/ --min-confidence 80 | grep -q 'unused function'"
- "test -f src/pipeline/transform.py"
wiring:
- source: "src/main.py"
pattern: "from pipeline.transform import TransformStage"
description: "Transform stage imported in main pipeline"yaml
stages:
- id: verify-pipeline
name: "Verify Data Pipeline"
stage_type: integration-verify
working_dir: "pipeline"
acceptance:
- "pytest"
- "vulture src/ --min-confidence 80"
- "mypy src/"
truths:
- "! vulture src/ --min-confidence 80 | grep -q 'unused function'"
- "test -f src/pipeline/transform.py"
wiring:
- source: "src/main.py"
pattern: "from pipeline.transform import TransformStage"
description: "Transform stage imported in main pipeline"Example 4: Go Microservice
示例4:Go微服务
yaml
stages:
- id: verify-service
name: "Verify Microservice"
stage_type: integration-verify
working_dir: "service"
acceptance:
- "go test ./..."
- "staticcheck ./..."
- "go build"
truths:
- "! staticcheck ./... | grep -q 'U1000'"
- "! staticcheck ./... | grep -q 'is unused'"
- "test -f cmd/server/main.go"yaml
stages:
- id: verify-service
name: "Verify Microservice"
stage_type: integration-verify
working_dir: "service"
acceptance:
- "go test ./..."
- "staticcheck ./..."
- "go build"
truths:
- "! staticcheck ./... | grep -q 'U1000'"
- "! staticcheck ./... | grep -q 'is unused'"
- "test -f cmd/server/main.go"Summary
总结
Dead code detection is a powerful verification tool for loom plans:
- Catches incomplete wiring: Code exists but isn't called = feature not integrated
- Language-specific tools: Rust (clippy), TypeScript (ts-prune), Python (vulture), Go (staticcheck), JavaScript (unimported)
- Best in integration-verify: Final quality gate after all implementation stages
- Combine with wiring checks: Dead code detection + wiring patterns + functional tests = comprehensive verification
- Handle false positives: Entry points, tests, framework magic — configure tools appropriately
- Working directory matters: Set to where build tools expect (where Cargo.toml, package.json, go.mod exist)
working_dir
Use this skill when designing verification strategies for loom plans. Copy-paste the YAML templates and adapt tool configurations to your project's structure.
死代码检测是Loom计划验证的强大工具:
- 捕获未完成集成:代码存在但未被调用 = 功能未集成
- 多语言工具支持:Rust(clippy)、TypeScript(ts-prune)、Python(vulture)、Go(staticcheck)、JavaScript(unimported)
- 最佳位置:集成验证阶段:所有实现阶段后的最终质量关卡
- 与集成检查结合:死代码检测 + 集成匹配规则 + 功能测试 = 全面验证
- 处理误报:入口点、测试代码、框架魔术特性等 - 合理配置工具
- 工作目录很重要:将设置为构建工具期望的目录(Cargo.toml、package.json、go.mod所在位置)
working_dir
在设计Loom计划的验证策略时使用该技能。可直接复制粘贴YAML模板,并根据项目结构调整工具配置。