analyzer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package analyzer provides functions and types for analyzing code coverage and exclusions in the uncloak application.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBelowThreshold is returned when the new code coverage is below the
	// configured threshold.
	ErrBelowThreshold = errors.New("new code coverage below threshold")
)

Functions

This section is empty.

Types

type FileReport

type FileReport struct {
	Path                   string
	CoveredNewLines        []int
	CoveredNewLineGroups   []LineRange
	UncoveredNewLines      []int
	UncoveredNewLineGroups []LineRange
}

FileReport represents the coverage report for a single file, including covered and uncovered new lines and their respective ranges.

func NewFileReport

func NewFileReport(path string) *FileReport

NewFileReport creates a new FileReport instance for the given file path.

func (*FileReport) GroupCoveredLines

func (fr *FileReport) GroupCoveredLines()

GroupCoveredLines groups the covered new lines in the file into ranges of consecutive lines.

func (*FileReport) GroupUncoveredLines

func (fr *FileReport) GroupUncoveredLines()

GroupUncoveredLines groups the uncovered new lines in the file into ranges of consecutive lines.

func (*FileReport) TotalNewLines

func (fr *FileReport) TotalNewLines() int

TotalNewLines returns the total number of new lines in the file report, which is the sum of covered and uncovered new lines.

type LineRange

type LineRange struct {
	Start int
	End   int
}

LineRange represents a continuous range of lines in a file, with a start and end line number.

type Report

type Report struct {
	CoverageThreshold float64
	CoverageProfile   *gocover.Profile
	GitDiffResults    *gitdiff.Results
	Files             []*FileReport
}

Report represents the analysis report for a Go project, including the coverage threshold, coverage profile, git diff results, and file-specific reports.

func NewCodeCoverage

func NewCodeCoverage(cfg *config.Config) (*Report, error)

NewCodeCoverage analyzes the Go coverage profile and the git diff file, returning a report of the coverage of new lines in the code. It returns a Report of the analyzed coverage and an error if any occurs during the analysis. If the coverage of new lines is below the threshold specified in the configuration, it returns ErrBelowThreshold as the error.

func NewReport

func NewReport(coverageThreshold float64, coverageProfile *gocover.Profile, gitDiff *gitdiff.Results) *Report

NewReport creates a new Report instance with the provided coverage threshold, coverage profile, and git diff.

func (*Report) CoveragePercent

func (r *Report) CoveragePercent() float64

CoveragePercent calculates and returns the coverage percentage of new lines in the report.

func (*Report) GroupCoveredLines

func (r *Report) GroupCoveredLines()

GroupCoveredLines groups the covered new lines in each file into ranges of consecutive lines.

func (*Report) GroupUncoveredLines

func (r *Report) GroupUncoveredLines()

GroupUncoveredLines groups the uncovered new lines in each file into ranges of consecutive lines.

func (*Report) HasUncoveredLines

func (r *Report) HasUncoveredLines() bool

HasUncoveredLines checks if there are any uncovered new lines in the report.

func (*Report) TotalCoveredNewLines

func (r *Report) TotalCoveredNewLines() int

TotalCoveredNewLines calculates and returns the total number of covered new lines across all files in the report.

func (*Report) TotalNewLines

func (r *Report) TotalNewLines() int

TotalNewLines calculates and returns the total number of new lines across all files in the report.

Jump to

Keyboard shortcuts

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