Metastatic.Analysis.DeadCode.Result
(Metastatic v0.10.4)
View Source
Result structure for dead code analysis.
Contains information about detected dead code locations, their types, and suggestions for remediation.
Fields
:has_dead_code?- Boolean indicating if any dead code was found:dead_locations- List of dead code locations with details:summary- Human-readable summary of findings:total_dead_statements- Count of dead statements detected:by_type- Map of dead code counts by type
Dead Code Types
:unreachable_after_return- Code after early return/break:constant_conditional- Unreachable branch of constant conditional:unused_function- Function defined but never called:unreachable_code- Other unreachable code patterns
Examples
iex> result = Metastatic.Analysis.DeadCode.Result.new([])
iex> result.has_dead_code?
false
iex> locations = [%{type: :unreachable_after_return, line: 42, confidence: :high}]
iex> result = Metastatic.Analysis.DeadCode.Result.new(locations)
iex> result.has_dead_code?
true
iex> result.total_dead_statements
1
Summary
Functions
Creates a new result from a list of dead code locations.
Creates a result with no dead code.
Converts result to JSON-compatible map.
Types
@type dead_code_type() ::
:unreachable_after_return
| :constant_conditional
| :unused_function
| :unreachable_code
@type dead_location() :: %{ type: dead_code_type(), reason: String.t(), confidence: :high | :medium | :low, suggestion: String.t(), context: term() }
@type t() :: %Metastatic.Analysis.DeadCode.Result{ by_type: %{required(dead_code_type()) => non_neg_integer()}, dead_locations: [dead_location()], has_dead_code?: boolean(), summary: String.t(), total_dead_statements: non_neg_integer() }
Functions
@spec new([dead_location()]) :: t()
Creates a new result from a list of dead code locations.
Examples
iex> Metastatic.Analysis.DeadCode.Result.new([])
%Metastatic.Analysis.DeadCode.Result{has_dead_code?: false, summary: "No dead code detected"}
iex> locations = [%{type: :unreachable_after_return, reason: "test", confidence: :high, suggestion: "remove", context: nil}]
iex> result = Metastatic.Analysis.DeadCode.Result.new(locations)
iex> result.has_dead_code?
true
@spec no_dead_code() :: t()
Creates a result with no dead code.
Examples
iex> result = Metastatic.Analysis.DeadCode.Result.no_dead_code()
iex> result.has_dead_code?
false
Converts result to JSON-compatible map.
Examples
iex> result = Metastatic.Analysis.DeadCode.Result.new([])
iex> map = Metastatic.Analysis.DeadCode.Result.to_map(result)
iex> is_map(map)
true