Search documentation of Metastatic

# Metastatic.Analysis.DeadCode.Result (Metastatic v0.13.2)

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

### Types

dead_code_type()
dead_location()
t()

### Functions

new(dead_locations)

Creates a new result from a list of dead code locations.

no_dead_code()

Creates a result with no dead code.

to_map(result)

Converts result to JSON-compatible map.

## Types

# dead_code_type()

    @type dead_code_type() ::
      :unreachable_after_return
      | :constant_conditional
      | :unused_function
      | :unreachable_code

# dead_location()

    @type dead_location() :: %{
      type: dead_code_type(),
      reason: String.t(),
      confidence: :high | :medium | :low,
      suggestion: String.t(),
      context: term()
    }

# t()

    @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

# new(dead_locations)

    @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

# no_dead_code()

    @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

# to_map(result)

    @spec to_map(t()) :: map()

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