Skip to content

Detector: Dead Code

Jacob Centner edited this page Apr 10, 2026 · 1 revision

Detector: Dead Code

Identifies exported functions, classes, and constants that are never imported elsewhere in the codebase.

Property Value
Name dead-code
Tier HEURISTIC
Languages Python, JavaScript/TypeScript
External tool None (Python ast + regex)
LLM required No
Confidence 0.70 (Python), 0.60 (JS/TS)

What it detects

Exported symbols (functions, classes, constants) that are never imported or referenced by any other module in the codebase.

How it works

Python

  1. Parses each module with ast to collect exported names
  2. Respects __all__ — if defined, only those names are considered exports
  3. Skips private/underscore-prefixed names, __init__.py, conftest.py, setup.py
  4. Tracks intra-file references (an exported function used within its own module is not dead)
  5. Cross-references all imports across the codebase

JavaScript/TypeScript

  1. Uses regex to extract export declarations
  2. Tracks import statements and dynamic import() calls
  3. Skips auto-generated files (detected by header comment patterns)
  4. Extensive _JS_ALWAYS_USED allowlist for framework hooks (Next.js, React, test lifecycle)

Allowlists

  • Python: ~80+ names including dunder methods (__init__, __str__), framework hooks (setUp, tearDown), test fixtures, PEP 517 build hooks
  • JS/TS: Next.js lifecycle (getServerSideProps, generateMetadata), test hooks (beforeEach, afterAll), HTTP handlers

Example finding

[DEAD-CODE] src/sentinel/core/runner.py:_legacy_format_output
  Exported function never imported elsewhere in the codebase
  Severity: LOW, Confidence: 0.70

Observed accuracy

Repo Findings TP Rate Notes
pip-tools 0 N/A Clean
httpx 0 N/A Clean
shadcn-ui/ui 1692 ~1% JS monorepo — dynamic imports, registry patterns
bubbletea 0 N/A Go not supported

Known limitations

  • JS/TS monorepos: High false-positive rate when exports are consumed via dynamic import(), registry patterns, or cross-package barrel re-exports. The lower 0.60 confidence reflects this.
  • Does not track re-exports across package boundaries in monorepos
  • No Go or Rust support

Clone this wiki locally