comparison

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparator

type Comparator struct {
	// contains filtered or unexported fields
}

Comparator compares analysis results to identify trends and changes.

The comparator takes two AnalysisResults (current and previous) and generates a ComparisonResult showing:

  • Metric deltas (changes in numeric values)
  • Trends (improving, worsening, or stable)
  • Issue changes (new issues, fixed issues)

Used for historical comparison when --compare flag is used.

func NewComparator

func NewComparator(stableThreshold float64) *Comparator

NewComparator creates a new comparator with the given stable threshold.

The stable threshold determines what percentage change is considered "stable" vs "improving/worsening". For example, with a 5% threshold:

  • Complexity change of 2% is "stable"
  • Complexity change of 8% is "improving" or "worsening"

Parameters:

  • stableThreshold: Percentage (0-100) for stable detection (e.g., 5.0 for 5%)

Example:

comp := NewComparator(5.0)
result := comp.Compare(currentResult, previousResult)

func (*Comparator) Compare

func (c *Comparator) Compare(current, previous *analyzer.AnalysisResult, previousTimestamp time.Time) *ComparisonResult

Compare generates a comparison between current and previous analysis results.

Returns nil if previous is nil (nothing to compare against). Calculates deltas for all metrics, detects trends, and categorizes issues.

Parameters:

  • current: The current analysis result
  • previous: The previous analysis result to compare against
  • previousTimestamp: The timestamp of the previous report

Returns:

  • ComparisonResult with deltas, trends, and issue changes

Example:

comp := NewComparator(5.0)
comparison := comp.Compare(currentResult, previousResult, previousTimestamp)
if comparison.Trends.Complexity == TrendImproving {
    fmt.Println("Complexity is improving!")
}

type ComparisonResult

type ComparisonResult struct {
	Current           *analyzer.AnalysisResult
	Previous          *analyzer.AnalysisResult
	PreviousTimestamp time.Time // Timestamp of the previous report
	Deltas            *MetricDeltas
	Trends            *Trends
	NewIssues         []*analyzer.Issue
	FixedIssues       []*analyzer.Issue
}

ComparisonResult contains the results of comparing two analysis runs.

type FloatDelta

type FloatDelta struct {
	Previous float64
	Current  float64
	Change   float64
	Percent  float64
}

FloatDelta represents a change in a float metric.

type IntDelta

type IntDelta struct {
	Previous int
	Current  int
	Change   int
	Percent  float64
}

IntDelta represents a change in an integer metric.

type MetricDeltas

type MetricDeltas struct {
	TotalFiles     IntDelta
	TotalLines     IntDelta
	TotalFunctions IntDelta
	AvgComplexity  FloatDelta
	AvgCoverage    FloatDelta
	IssueCount     IntDelta
}

MetricDeltas contains the changes in metrics between two runs.

type TrendDirection

type TrendDirection int

TrendDirection indicates whether a metric is improving, worsening, or stable.

const (
	TrendStable TrendDirection = iota
	TrendImproving
	TrendWorsening
)

func (TrendDirection) Icon

func (t TrendDirection) Icon() string

Icon returns an emoji icon representing the trend.

func (TrendDirection) String

func (t TrendDirection) String() string

String returns a human-readable representation of the trend.

type Trends struct {
	Complexity TrendDirection
	Coverage   TrendDirection
	IssueCount TrendDirection
}

Trends indicates the direction of change for key metrics.

Jump to

Keyboard shortcuts

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