Skip to main content

Core analyzer

Dead Code Detection

Detects unreachable code, dead branches, unused private members, and unused exports.

technical-debt core-dead-code

Dead Code Detection

Detects unreachable code, dead branches, unused private members, and unused exports.

Dead code is JavaScript or TypeScript that cannot affect program behavior: statements after a terminal return, branches whose condition is a literal true or false, private class members the class never refers to, and exports nobody imports. It survives in codebases because removing it requires confidence that no one else relies on it.

Vipr's detector has two layers. Per file, it reads the syntax tree: unreachable statements, dead branches and unused private members are properties of one file and are reported with high confidence. Across files, it builds an export graph from the complete set of project files the client registered and reports exports that no file of that set imports. When no file set was registered, the project is unknown and no unused export is reported at all.

The dead-code score belongs to the file. It combines how much of the file is dead (dead lines over total lines) with a bounded term for the number of findings: 100 - 70 x density - 30 x items / (items + 10). Unused exports are listed and counted, but they depend on other files and do not move the score.

Severity guide

info
Low-confidence unused export. Something in the project could consume it in a way the analyzer cannot follow: a dynamic import or require with a computed path can reach the module, or an import elsewhere could not be resolved and may refer to it. Verify before removing.
warning
High-confidence finding. Unreachable code, a dead branch or an unused private member read from the file itself; or an export that no file of the registered project imports, with every import resolved. A consumer outside the registered file set is not visible.
critical
Not currently emitted by this analysis.

Remediation

Verify the dead code is unused (especially for low-confidence exports) and either delete it or suppress the insight.

  • For unreachable code: delete the statements after the terminal. If they represented intended fallback logic, move them before the terminal or restructure the control flow.
  • For dead branches: remove the conditional and keep the branch that always executes. Check for leftover debug flags or partially-completed refactors.
  • For unused private members: confirm no dynamic access patterns reference them, then delete the declaration.
  • For unused exports: check that nothing outside the analyzed file set imports it (another repository, a published API, test files excluded from the scan), then remove the export keyword or the declaration. When the finding is on a re-export line (export { x } from './m'), remove the name from that re-export; the declaration lives in the other module and may still be used there. Low-confidence findings need verification first: a dynamic import with a computed path or an unresolved import may consume them.
Documentation