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 with constant-folded conditions, private class members with no internal references, and exports nobody imports. It survives in codebases because removing it requires confidence that no one else relies on it.
Vipr's detector combines intra-file AST analysis (reliable, high-confidence) with cross-file export-graph analysis (project-wide, lower-confidence when the project boundary is unclear). Each finding carries a confidence level reflecting how certain the detector is that the code is truly unused.
Severity guide
- info
- Medium- or low-confidence finding. Verify the code is unused — external consumers or dynamic imports may not be visible to the analyzer.
- warning
- High-confidence finding. The detector has strong evidence the code is unreachable or unreferenced within the analyzed scope.
- 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: high-confidence findings are usually safe to delete. Low-confidence findings need verification — external packages, dynamic imports, or re-exports through barrels may consume them invisibly.