| title | Dead Code Analysis in ReScript |
|---|---|
| metaTitle | Dead Code Analysis in ReScript |
| description | Documentation about ReScript editor plugins and code analysis |
| canonical | /docs/manual/editor-code-analysis |
| section | Guides |
| order | 2 |
This guide provides a detailed walkthrough on how to leverage ReScript’s powerful dead code analysis tools to maintain a clean, efficient, and distraction-free codebase.
Dead code refers to code that's present in your codebase but is never executed. It can lead to:
- Increased compilation times
- Confusion during development
- Misleading assumptions about functionality
ReScript’s language design allows for accurate and efficient dead code analysis using the ReScript Code Analyzer, available via the official VSCode extension. This is useful for manual refactors and for developers using agents, because fast project-wide feedback helps catch incorrect assumptions early.
- ReScript VSCode extension (v1.8.2 or higher)
- Open the Command Palette:
Cmd/Ctrl + P - Run:
> ReScript: Start Code Analyzer
- Run:
> ReScript: Stop Code Analyzer - Or click “Stop Code Analyzer” in the status bar
- The “Problems” pane populates with dead code warnings and suggestions.
Reactive dead code updates are a newer enhancement of Editor Code Analysis and require ReScript VSCode extension v1.73.9 or higher (pre-release).
type useReturn = {
items: array<item>,
toggleItemChecked: string => unit, // ← Never used
setCheckedOnItem: (string, bool) => unit,
checkAll: unit => unit,
uncheckAll: unit => unit,
}Remove unused fields to simplify code.
type textType =
| Text(string)
| TextWithIcon({icon: React.element, text: string})
| Render(React.element) // ← Never constructedRemoving unused variants allows simplifying rendering logic.
type validationState = Idle | Invalid | Valid
type state = {
oldPassword: string,
newPassword: string,
newPasswordRepeated: string,
validationState: validationState, // ← Never read
}Old validation logic might remain after refactors—clean it up.
// DrilldownTarget.resi
MetricParam.parse // ← Never used
MetricParam.serialize // ← Never usedKeep interfaces minimal by removing unused exports.
let routerUrlToPath = ... // ← Never used
let routeUrlStartsWith = ... // ← Never usedRemoving these often uncovers further unused logic.
Components never referenced in production should be removed, unless explicitly preserved.
Suppresses warnings but notifies if code becomes alive again.
type user = {
name: string,
@dead age: int,
}Permanently marks code as alive (no future warnings).
@live
let getUserName = user => user.nameAdd to your rescript.json:
"reanalyze": {
"analysis": ["dce"],
"suppress": ["src/bindings", "src/stories", "src/routes"],
"unsuppress": [],
"transitive": false
}- analysis: Enables dead code analysis (
"dce") - suppress: Silences reporting for paths (still analyzes)
- unsuppress: Re-enables reports within suppressed paths
- transitive: Controls reporting of indirectly dead code
Recommendation: Set transitive: false for incremental cleanup.
ReScript’s dead code analyzer helps you:
- Incrementally clean up your codebase
- Avoid confusion and complexity
- Improve long-term maintainability
Use it regularly for the best results.