MetaCredo. Analysis. Complexity
(MetaCredo v0.3.4)
View Source
Programmatic complexity analysis API.
Provides access to comprehensive code complexity metrics that work uniformly across all supported languages by operating on the unified MetaAST representation.
Metrics
- Cyclomatic Complexity -- McCabe metric, decision points + 1
- Cognitive Complexity -- Structural complexity with nesting penalties
- Nesting Depth -- Maximum nesting level
- Halstead Metrics -- Volume, difficulty, effort
- Lines of Code -- Physical, logical, comments
- Function Metrics -- Statements, returns, variables
Usage
alias Metastatic.Document
alias MetaCredo.Analysis.Complexity
doc = Document.new(ast, :elixir)
{:ok, result} = Complexity.analyze(doc)
result.cyclomatic # => 2
result.cognitive # => 1
result.max_nesting # => 1
Summary
Functions
@spec analyze(Metastatic.Document.t()) :: {:ok, term()} | {:error, term()}
Analyzes a document for complexity.
Returns {:ok, result} where result is a MetaCredo.Analysis.Complexity.Result struct.
Options
:thresholds- Threshold map for warnings:metrics- List of metrics to calculate (default::all)
@spec analyze!(Metastatic.Document.t()) :: term()
Analyzes a document for complexity.
Returns {:ok, result} where result is a MetaCredo.Analysis.Complexity.Result struct.
Options
:thresholds- Threshold map for warnings:metrics- List of metrics to calculate (default::all)
Unlike not-banged version, this one either returns a result or raises