complexity

package
v0.9.45 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package complexity provides the repository's versioned cyclomatic-complexity analysis. Its counting rules deliberately match plans/go-complexity-reduction.md: one plus if/for/range/non-default switch or select cases and &&/||. Decisions in function literals are attributed to the nearest named declaration (or to a package-level function-valued initializer), so the scope is stable over time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(report Report) ([]byte, error)

Encode writes a reproducibly formatted report.

func Key

func Key(f Function) string

Key is the stable baseline identity of a function.

Types

type File

type File struct {
	Module  string `json:"module"`
	Package string `json:"package"`
	Path    string `json:"path"`
	Lines   int    `json:"lines"`
	Test    bool   `json:"test,omitempty"`
}

File records every analyzed source file, including files without functions.

type Function

type Function struct {
	Module     string `json:"module"`
	Package    string `json:"package"`
	Path       string `json:"path"`
	Receiver   string `json:"receiver,omitempty"`
	Name       string `json:"name"`
	Complexity int    `json:"complexity"`
	Lines      int    `json:"lines"`
	FileLines  int    `json:"file_lines"`
	Test       bool   `json:"test,omitempty"`
}

Function identifies and measures a function or method.

type Options

type Options struct {
	IncludeTests bool
}

Options controls repository traversal.

type Report

type Report struct {
	CountingRules string     `json:"counting_rules"`
	Files         []File     `json:"files"`
	Functions     []Function `json:"functions"`
}

Report is stable, machine-readable analysis output.

func Analyze

func Analyze(root string, opts Options) (Report, error)

Analyze walks root, including nested modules and platform-specific source.

Jump to

Keyboard shortcuts

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