complexity

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package complexity provides AST-based complexity analysis for functions across 206 languages using gotreesitter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnrichWithXref

func EnrichWithXref(report *Report, graph xref.Graph)

EnrichWithXref populates fan-in and fan-out metrics by matching functions against xref definitions.

Types

type FunctionMetrics

type FunctionMetrics struct {
	File       string `json:"file"`
	Name       string `json:"name"`
	Kind       string `json:"kind"`
	Language   string `json:"language"`
	StartLine  int    `json:"start_line"`
	EndLine    int    `json:"end_line"`
	Lines      int    `json:"lines"`
	Cyclomatic int    `json:"cyclomatic"`
	Cognitive  int    `json:"cognitive"`
	MaxNesting int    `json:"max_nesting"`
	Parameters int    `json:"parameters"`
	FanIn      int    `json:"fan_in"`
	FanOut     int    `json:"fan_out"`
	Returns    int    `json:"returns"`
	BoolDepth  int    `json:"bool_depth"`
}

FunctionMetrics holds all computed complexity metrics for a single function or method.

type Options

type Options struct {
	MinCyclomatic int
	Sort          string // "cyclomatic", "cognitive", "lines", "nesting"
	Top           int
}

Options controls filtering, sorting, and limiting of the analysis output.

type Report

type Report struct {
	Functions []FunctionMetrics `json:"functions"`
	Summary   Summary           `json:"summary"`
}

Report contains the full complexity analysis result.

func Analyze

func Analyze(idx *model.Index, root string, opts Options) (*Report, error)

Analyze computes complexity metrics for every function/method in the index.

type Summary

type Summary struct {
	Count         int     `json:"count"`
	AvgCyclomatic float64 `json:"avg_cyclomatic"`
	MaxCyclomatic int     `json:"max_cyclomatic"`
	P90Cyclomatic int     `json:"p90_cyclomatic"`
	AvgCognitive  float64 `json:"avg_cognitive"`
	MaxCognitive  int     `json:"max_cognitive"`
	AvgLines      float64 `json:"avg_lines"`
	MaxLines      int     `json:"max_lines"`
	AvgMaxNesting float64 `json:"avg_max_nesting"`
}

Summary holds aggregate statistics across all analyzed functions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL