Metastatic.Analysis.DeadCodeAnalyzer
(Metastatic v0.10.4)
View Source
Plugin analyzer wrapper for dead code detection.
This module wraps the existing Metastatic.Analysis.DeadCode module as an
Analyzer behaviour plugin for use with the Runner system. It detects:
- Unreachable code after returns - Code following early_return nodes
- Constant conditionals - Branches that can never execute (if true/false)
- Other dead patterns - Unused assignments, etc.
Usage
alias Metastatic.{Document, Analysis.Runner}
# Register as plugin
Registry.register(DeadCodeAnalyzer)
# Run via Runner
{:ok, report} = Runner.run(doc)Configuration
:min_confidence- Minimum confidence to report (default: :low):low- Report all dead code:medium- Report high-confidence issues only:high- Report only definite dead code
Examples
# Unreachable after return
iex> ast = {:block, [], [
...> {:early_return, [], [{:literal, [subtype: :integer], 1}]},
...> {:literal, [subtype: :integer], 2}
...> ]}
iex> doc = Metastatic.Document.new(ast, :python)
iex> {:ok, report} = Metastatic.Analysis.Runner.run(doc,
...> analyzers: [Metastatic.Analysis.DeadCodeAnalyzer])
iex> length(report.issues)
1
iex> [issue | _] = report.issues
iex> issue.category
:correctness