Metastatic.Analysis.NestingDepth (Metastatic v0.10.4)

View Source

Detects excessive nesting depth in code.

High nesting depth makes code harder to understand and maintain. This analyzer identifies nodes that exceed a configurable nesting threshold and suggests refactoring to reduce complexity.

Works across all supported languages by operating on the unified MetaAST.

Configuration

  • :max_depth - Maximum allowed nesting depth (default: 5)
  • :warn_threshold - Depth at which warnings are issued (default: 4)

Examples

alias Metastatic.{Document, Analysis.Runner}

# As plugin
Registry.register(NestingDepth)
{:ok, report} = Runner.run(doc,
  config: %{nesting_depth: %{max_depth: 4}}
)

Nesting Examples

# Depth 0: No nesting
x = 5

# Depth 1: One conditional
if x > 0 then y = 1 end

# Depth 2: Nested conditionals
if x > 0 then
  if y > 0 then z = 1 end
end

# Depth 3+: Excessive nesting
if a then
  if b then
    if c then
      result = 1
    end
  end
end