Search documentation of Metastatic

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

View Source

Result structure for unused variable analysis.

Contains information about variables that are assigned but never read, including their locations, types, and suggestions for remediation.

## Fields

- `:has_unused?` - Boolean indicating if any unused variables were found
- `:unused_variables` - List of unused variable details
- `:summary` - Human-readable summary of findings
- `:total_unused` - Count of unused variables
- `:by_category` - Map of counts by category

## Variable Categories

- `:local` - Local variable assigned but not read
- `:parameter` - Function parameter never used
- `:iterator` - Loop iterator never accessed
- `:pattern` - Pattern match binding never used

## Examples

    iex> result = Metastatic.Analysis.UnusedVariables.Result.new([])
    iex> result.has_unused?
    false

    iex> vars = [%{name: "x", category: :local, line: 10}]
    iex> result = Metastatic.Analysis.UnusedVariables.Result.new(vars)
    iex> result.has_unused?
    true
    iex> result.total_unused
    1

## Summary

### Types

category()
t()
unused_variable()

### Functions

new(unused_variables)

Creates a new result from a list of unused variables.

no_unused()

Creates a result with no unused variables.

to_map(result)

Converts result to JSON-compatible map.

## Types

# category()

    @type category() :: :local | :parameter | :iterator | :pattern

# t()

    @type t() :: %Metastatic.Analysis.UnusedVariables.Result{
      by_category: %{required(category()) => non_neg_integer()},
      has_unused?: boolean(),
      summary: String.t(),
      total_unused: non_neg_integer(),
      unused_variables: [unused_variable()]
    }

# unused_variable()

    @type unused_variable() :: %{
      name: String.t(),
      category: category(),
      suggestion: String.t(),
      context: term()
    }

## Functions

# new(unused_variables)

    @spec new([unused_variable()]) :: t()

Creates a new result from a list of unused variables.

## Examples

    iex> Metastatic.Analysis.UnusedVariables.Result.new([])
    %Metastatic.Analysis.UnusedVariables.Result{has_unused?: false, summary: "No unused variables detected"}

    iex> vars = [%{name: "x", category: :local, suggestion: "remove", context: nil}]
    iex> result = Metastatic.Analysis.UnusedVariables.Result.new(vars)
    iex> result.has_unused?
    true

# no_unused()

    @spec no_unused() :: t()

Creates a result with no unused variables.

## Examples

    iex> result = Metastatic.Analysis.UnusedVariables.Result.no_unused()
    iex> result.has_unused?
    false

# to_map(result)

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

Converts result to JSON-compatible map.

## Examples

    iex> result = Metastatic.Analysis.UnusedVariables.Result.new([])
    iex> map = Metastatic.Analysis.UnusedVariables.Result.to_map(result)
    iex> is_map(map)
    true