model

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package model defines the normalized coverage model that cover100 collects from every supported language and hands to the treemap UI.

The model is deliberately language-neutral: collectors (internal/gocov, internal/tscov) produce FileCoverage values, and aggregation (internal/aggregate) rolls them up into a single Node tree whose shape is repository -> package -> file -> function.

Index

Constants

View Source
const (
	TypeRoot       = "root"
	TypeRepository = "repository"
	TypePackage    = "package"
	TypeFile       = "file"
	TypeFunction   = "function"
)

Node types. The tree is always repository -> package -> file -> function; the root node is the synthetic parent of every repository.

View Source
const (
	LangGo         = "go"
	LangTypeScript = "typescript"
	LangJavaScript = "javascript"
	LangMixed      = "mixed"
)

Languages reported per node and used by the UI's language filter.

Variables

View Source
var MetricNames = []string{"lines", "functions", "files", "packages", "repositories"}

MetricNames is the canonical metric order exposed in the report and UI.

Functions

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to b.

func IntPtr

func IntPtr(i int) *int

IntPtr returns a pointer to i.

func StrPtr

func StrPtr(s string) *string

StrPtr returns a pointer to s, for the optional JSON fields above.

Types

type FileCoverage

type FileCoverage struct {
	Path     string
	Language string

	Lines    Metric
	Branches *Metric

	Functions          Metric
	FunctionsAvailable bool
	FunctionList       []FuncCoverage
}

FileCoverage is a collector's result for a single source file. Path is always relative to the scan root and slash-separated, which is what makes node IDs globally unique without a per-collector naming scheme.

type FuncCoverage

type FuncCoverage struct {
	Name    string
	Line    int
	Hits    int
	Lines   Metric
	Covered bool
}

FuncCoverage is per-function detail collected from a language that can supply it (currently Istanbul-format JavaScript/TypeScript reports).

type Metric

type Metric struct {
	Covered int `json:"covered"`
	Total   int `json:"total"`
}

Metric is a covered/total pair for a single coverage dimension.

func (Metric) Add

func (m Metric) Add(o Metric) Metric

Add returns the element-wise sum of two metrics.

func (Metric) Any

func (m Metric) Any() int

Any returns 1 when at least one unit in the dimension is covered, else 0. It implements the model's "a package/file counts as covered when any line inside it is covered" rule.

func (Metric) Percent

func (m Metric) Percent() (float64, bool)

Percent returns coverage as a fraction in [0,1]. ok is false when the dimension was not measured (Total == 0), which callers must render as "not measured" rather than as 0%.

type Metrics

type Metrics struct {
	Lines        Metric `json:"lines"`
	Functions    Metric `json:"functions"`
	Files        Metric `json:"files"`
	Packages     Metric `json:"packages"`
	Repositories Metric `json:"repositories"`
}

Metrics groups the five coverage dimensions reported for every tree node.

type Node

type Node struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Type string `json:"type"`
	// Language is nil on the root node and "mixed" for a repository that holds
	// more than one language.
	Language *string `json:"language"`
	// Path is relative to the repository root for packages and files, and
	// relative to the scan root for repositories.
	Path string `json:"path,omitempty"`

	// Function-only detail.
	Line    *int  `json:"line,omitempty"`
	Hits    *int  `json:"hits,omitempty"`
	Covered *bool `json:"covered,omitempty"`

	// FunctionsAvailable is present (and false) on Go files: Go's cover
	// profiles carry no function-level data, so functions are reported 0/0.
	FunctionsAvailable *bool   `json:"functionsAvailable,omitempty"`
	Branches           *Metric `json:"branches,omitempty"`

	Metrics

	Children []*Node `json:"children,omitempty"`
}

Node is one node of the aggregated coverage tree. Metrics is embedded so the five metric objects are serialized inline, exactly as the UI expects.

type Report

type Report struct {
	GeneratedAt string   `json:"generatedAt"`
	Root        string   `json:"root"`
	Metrics     []string `json:"metrics"`
	Languages   []string `json:"languages"`
	Tree        *Node    `json:"tree"`

	// Additive fields. Consumers that only understand the contract above can
	// ignore them; they exist so the CLI can report partial failures in-band.
	Warnings []string `json:"warnings,omitempty"`
	Tool     string   `json:"tool,omitempty"`
}

Report is the document written to --out and fetched by the treemap page.

Jump to

Keyboard shortcuts

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