metrics

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package metrics provides static code quality metrics such as cyclomatic complexity.

Package metrics provides analysis of code quality metrics such as dead code detection.

Package metrics provides analysis of code duplication between functions.

Package metrics provides analysis of code quality metrics such as global state usage.

Package metrics provides analysis of code quality metrics such as function and file size.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateComplexityReport added in v1.6.0

func GenerateComplexityReport(results []ComplexityResult) string

GenerateComplexityReport creates a formatted complexity report

func GenerateSizeReport added in v1.6.0

func GenerateSizeReport(functions []FunctionSize, files []FileSize) string

GenerateSizeReport creates a formatted size analysis report

Types

type ComplexityResult

type ComplexityResult struct {
	Name       string // Function name
	File       string // File path
	Line       int    // Line number
	Complexity int    // Computed cyclomatic complexity
	Exported   bool   // Whether function is exported
	Category   string // Function category (high, medium, low)
	Risk       string // Risk assessment
}

ComplexityResult represents the cyclomatic complexity of a single function.

func AnalyzeCyclomaticComplexity

func AnalyzeCyclomaticComplexity(files []string) ([]ComplexityResult, error)

AnalyzeCyclomaticComplexity calculates complexity for all functions in given files.

type ComplexitySummary added in v1.6.0

type ComplexitySummary struct {
	TotalFunctions    int
	HighComplexity    int
	MediumComplexity  int
	LowComplexity     int
	AverageComplexity float64
	MaxComplexity     int
	RiskDistribution  map[string]int
}

ComplexitySummary provides overall complexity statistics

func ComputeComplexitySummary added in v1.6.0

func ComputeComplexitySummary(results []ComplexityResult) ComplexitySummary

ComputeComplexitySummary calculates overall complexity statistics

type DeadFunction

type DeadFunction struct {
	Name     string // Fully-qualified function name
	Pos      string // File and line number
	Recv     string // Receiver type (for methods)
	PkgPath  string // Package where the function is defined
	IsExport bool   // Whether the function is exported
}

DeadFunction represents a function or method that is never used.

func AnalyzeDeadCode

func AnalyzeDeadCode(pattern string) ([]DeadFunction, error)

AnalyzeDeadCode analyzes all packages for unused (dead) functions.

type DupFn

type DupFn struct {
	Name string // Function name
	File string // File path
	Line int    // Line number
}

DupFn describes a single function instance within a duplicate block.

type DuplicateBlock

type DuplicateBlock struct {
	Hash  string  // Hash of normalized function body
	Funcs []DupFn // All functions that share this body
}

DuplicateBlock represents two or more identical function bodies across files.

func AnalyzeDuplicatedFunctions

func AnalyzeDuplicatedFunctions(files []string) ([]DuplicateBlock, error)

AnalyzeDuplicatedFunctions scans a list of Go files and reports duplicated function bodies.

type FileSize

type FileSize struct {
	File     string // File path
	LOC      int    // Total lines of code
	Category string // Size category
	Risk     string // Risk assessment
}

FileSize stores metrics about a file's total lines of code.

func AnalyzeFileSizes

func AnalyzeFileSizes(files []string) ([]FileSize, error)

AnalyzeFileSizes returns line counts for each provided Go source file.

type FunctionSize

type FunctionSize struct {
	Name     string // Function name
	LOC      int    // Lines of code
	File     string // File path
	Line     int    // Line number where the function starts
	Exported bool   // Whether function is exported
	Category string // Size category (large, medium, small)
	Risk     string // Risk assessment
}

FunctionSize stores metrics about a function's line length.

func AnalyzeFunctionSizes

func AnalyzeFunctionSizes(files []string) ([]FunctionSize, error)

AnalyzeFunctionSizes parses Go files and returns a list of function sizes.

type GlobalSymbol

type GlobalSymbol struct {
	Name     string // Symbol name
	Kind     string // "var" or "const"
	PkgPath  string // Full import path of the package
	File     string // File where symbol is defined
	Line     int    // Line number
	Exported bool   // Whether the symbol is exported
	Mutable  bool   // Whether the symbol is a variable (mutable)
	HasInit  bool   // Whether the symbol has an initializer
}

GlobalSymbol represents a global variable or constant in a package.

func AnalyzeGlobals

func AnalyzeGlobals(pattern string) ([]GlobalSymbol, error)

AnalyzeGlobals detects global variables and constants defined at package scope.

type SizeSummary added in v1.6.0

type SizeSummary struct {
	TotalFunctions   int
	LargeFunctions   int
	MediumFunctions  int
	SmallFunctions   int
	AverageLOC       float64
	MaxLOC           int
	TotalFiles       int
	LargeFiles       int
	MediumFiles      int
	SmallFiles       int
	RiskDistribution map[string]int
}

SizeSummary provides overall size statistics

func ComputeSizeSummary added in v1.6.0

func ComputeSizeSummary(functions []FunctionSize, files []FileSize) SizeSummary

ComputeSizeSummary calculates overall size statistics

Jump to

Keyboard shortcuts

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