diedeadcode
Conservative dead code detection for TypeScript and JavaScript.
ddd finds unused exports, unreachable functions, and dead code in your codebase with confidence scoring to minimize false positives.
Features
- Fast - Built on oxc for blazing-fast parsing
- Conservative - Confidence scoring reduces false positives
- Transitive analysis - Detects code that's only called by other dead code
- Framework-aware - Understands Next.js, Express, Jest, Vitest patterns
- Configurable - Ignore patterns, entry points, and more
Installation
npm (recommended)
Or run directly with npx:
Cargo
Homebrew (macOS)
Build from source
Quick Start
# Analyze current directory
# Analyze with verbose output
# Initialize config file
# Output as JSON
# Check mode (exit code 1 if dead code found, useful for CI)
Configuration
Run ddd init to generate a ddd.toml in your project root, or create one manually:
# Files to analyze
= ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"]
= ["**/node_modules/**", "**/dist/**", "**/*.test.*"]
# Entry points
[]
= ["src/index.ts", "src/main.ts"]
= ["**/pages/**/*.tsx"] # e.g., Next.js pages
= true # Detect from package.json
# Output settings
[]
= "table" # table, json, or compact
= "high" # high, medium, or low
= true
# Analysis settings
[]
= ["logger", "debug"]
= ["^_"] # Ignore symbols starting with _
How It Works
- Parse - Uses oxc to build an AST for each file
- Extract - Identifies all exports, functions, classes, and variables
- Graph - Builds a call graph tracking all references
- Propagate - BFS from entry points to find unreachable code
- Score - Assigns confidence based on patterns and heuristics
Confidence Scoring
Not all dead code warnings are equal. ddd scores each finding:
| Score | Meaning |
|---|---|
| 90-100 | High confidence - likely dead |
| 70-89 | Medium confidence - review recommended |
| <70 | Lower confidence - may be false positive |
Factors that reduce confidence:
- Dynamic imports (
import()) - Reflection (
eval,Reflect.*) - Decorated symbols (decorators often indicate framework usage)
- String property access patterns
- Exported symbols (may be used externally)
Output Formats
# Table (default)
# JSON for tooling integration
# Compact single-line per issue
Exit Codes
| Code | Meaning |
|---|---|
| 0 | No dead code found |
| 1 | Dead code found |
| 2 | Error during analysis |
Performance
ddd is designed for large codebases:
- Parallel file parsing with rayon
- Memory-efficient AST traversal
Contributing
See CONTRIBUTING.md for guidelines.
License
MIT - see LICENSE