Metastatic.Analysis.Registry (Metastatic v0.10.4)

View Source

Registry for analyzer plugins.

Manages registration, discovery, and configuration of analyzers. Runs as a GenServer under the application supervision tree.

Usage

# Register an analyzer
Registry.register(MyApp.Analysis.UnusedVariables)

# Look up by name
Registry.get_by_name(:unused_variables)

# Look up by category
Registry.list_by_category(:correctness)

# List all
Registry.list_all()

# Configure analyzer
Registry.configure(MyAnalyzer, %{threshold: 10})

Configuration

Auto-register analyzers at application startup:

# config/config.exs
config :metastatic, :analyzers,
  auto_register: [
    Metastatic.Analysis.UnusedVariables,
    Metastatic.Analysis.SimplifyConditional
  ],
  disabled: [:some_analyzer],
  config: %{
    unused_variables: %{ignore_prefix: "_"}
  }

Summary

Functions

Returns a specification to start this module under a supervisor.

Clears all registered analyzers.

Updates configuration for an analyzer.

Gets analyzer by name.

Gets configuration for an analyzer.

Lists all registered analyzers.

Lists analyzers by category.

Lists all available categories.

Registers an analyzer module.

Starts the registry GenServer.

Unregisters an analyzer module.

Types

registry_state()

@type registry_state() :: %{
  by_name: %{required(atom()) => module()},
  by_category: %{required(atom()) => [module()]},
  all: MapSet.t(module()),
  config: %{required(module()) => map()}
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

@spec clear() :: :ok

Clears all registered analyzers.

Primarily for testing purposes.

configure(analyzer, config)

@spec configure(module(), map()) :: :ok

Updates configuration for an analyzer.

Merges the new config with existing config.

Examples

iex> Registry.configure(MyAnalyzer, %{threshold: 10})
:ok

get_by_name(name)

@spec get_by_name(atom()) :: module() | nil

Gets analyzer by name.

Returns nil if no analyzer is registered with that name.

Examples

iex> Registry.get_by_name(:unused_variables)
MyApp.Analysis.UnusedVariables

iex> Registry.get_by_name(:nonexistent)
nil

get_config(analyzer)

@spec get_config(module()) :: map()

Gets configuration for an analyzer.

Returns empty map if no configuration is set.

Examples

iex> Registry.get_config(MyAnalyzer)
%{threshold: 10}

list_all()

@spec list_all() :: [module()]

Lists all registered analyzers.

Examples

iex> Registry.list_all()
[MyApp.Analysis.UnusedVariables, MyApp.Analysis.SimplifyConditional]

list_by_category(category)

@spec list_by_category(atom()) :: [module()]

Lists analyzers by category.

Examples

iex> Registry.list_by_category(:correctness)
[MyApp.Analysis.UnusedVariables, MyApp.Analysis.DeadCode]

list_categories()

@spec list_categories() :: [atom()]

Lists all available categories.

Examples

iex> Registry.list_categories()
[:correctness, :style, :refactoring, :maintainability]

register(analyzer)

@spec register(module()) :: :ok | {:error, String.t()}

Registers an analyzer module.

The module must implement the Metastatic.Analysis.Analyzer behaviour. Validates that no conflicts exist (another analyzer with same name).

Examples

iex> Registry.register(MyApp.Analysis.UnusedVariables)
:ok

iex> Registry.register(ConflictingAnalyzer)
{:error, "Analyzer named :unused_variables already registered: ..."}

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the registry GenServer.

Called automatically by the application supervision tree.

unregister(analyzer)

@spec unregister(module()) :: :ok

Unregisters an analyzer module.

Removes the analyzer from the registry.

Examples

iex> Registry.unregister(MyApp.Analysis.UnusedVariables)
:ok