report

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package report provides a pluggable section registry for stringer report. Each section consumes metrics from collectors and renders a focused analysis.

Index

Constants

View Source
const (
	SeverityHigh   = "high"
	SeverityMedium = "medium"
	SeverityLow    = "low"
)

Severity levels for recommendations.

Variables

View Source
var ErrMetricsNotAvailable = errors.New("metrics not available")

ErrMetricsNotAvailable indicates a section's required metrics are missing, typically because the corresponding collector was not run.

Functions

func ColorAssessment

func ColorAssessment(val string) string

ColorAssessment colors test coverage assessments.

func ColorRiskLevel

func ColorRiskLevel(val string) string

ColorRiskLevel colors CRITICAL/WARNING/ok risk labels.

func ColorStability

func ColorStability(val string) string

ColorStability colors stability labels.

func List

func List() []string

List returns the names of all registered sections in registration order.

func Register

func Register(s Section)

Register adds a section to the global registry. It panics if a section with the same name is already registered.

func RenderJSON added in v0.6.0

func RenderJSON(result *signal.ScanResult, repoPath string, collectorNames []string, sections []string, w interface{ Write([]byte) (int, error) }) error

RenderJSON writes the report as machine-readable JSON.

func ResolveSections added in v0.6.0

func ResolveSections(filter []string) []string

ResolveSections determines which sections to run without printing warnings. If filter is empty, all registered sections are used.

func SectionTitle

func SectionTitle(title string) string

SectionTitle renders a bold section title.

Types

type Alignment

type Alignment int

Alignment controls how a column's content is justified.

const (
	// AlignLeft pads on the right (default).
	AlignLeft Alignment = iota
	// AlignRight pads on the left.
	AlignRight
)

type CollectorResultJSON added in v0.6.0

type CollectorResultJSON struct {
	Name       string `json:"name"`
	Signals    int    `json:"signals"`
	Duration   string `json:"duration"`
	Error      string `json:"error,omitempty"`
	HasMetrics bool   `json:"has_metrics"`
}

CollectorResultJSON is the JSON representation of a single collector result.

type ColorFunc

type ColorFunc func(value string) string

ColorFunc maps a cell value to a colored string. If nil, no color is applied.

type Column

type Column struct {
	Header string
	Align  Alignment
	Color  ColorFunc // optional per-cell color function
}

Column describes a single table column.

type Recommendation

type Recommendation struct {
	Severity string
	Message  string
}

Recommendation is a single actionable suggestion derived from metrics.

type ReportJSON added in v0.6.0

type ReportJSON struct {
	Repository string                `json:"repository"`
	Generated  string                `json:"generated"`
	Duration   string                `json:"duration"`
	Collectors []CollectorResultJSON `json:"collectors"`
	Signals    SignalSummaryJSON     `json:"signals"`
	Sections   []SectionJSON         `json:"sections,omitempty"`
}

ReportJSON is the top-level JSON structure for --format json output.

type Section

type Section interface {
	// Name returns the unique identifier for this section (e.g., "lottery-risk").
	Name() string

	// Description returns a human-readable description of what this section reports.
	Description() string

	// Analyze processes the scan result and prepares internal state for rendering.
	// Returns ErrMetricsNotAvailable (wrapped) if required metrics are missing.
	Analyze(result *signal.ScanResult) error

	// Render writes the section output to w.
	Render(w io.Writer) error
}

Section is a pluggable report section that analyzes scan results and renders a focused report segment.

func Get

func Get(name string) Section

Get returns the section with the given name, or nil if not found.

type SectionJSON added in v0.6.0

type SectionJSON struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Status      string `json:"status"`            // "ok", "skipped"
	Content     string `json:"content,omitempty"` // rendered text
}

SectionJSON is the JSON representation of a single report section.

type SignalSummaryJSON added in v0.6.0

type SignalSummaryJSON struct {
	Total  int            `json:"total"`
	ByKind map[string]int `json:"by_kind"`
}

SignalSummaryJSON is the JSON representation of the signal summary.

type Table

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

Table renders aligned text tables to an io.Writer.

func NewTable

func NewTable(columns ...Column) *Table

NewTable creates a table with the given column definitions.

func (*Table) AddRow

func (t *Table) AddRow(values ...string)

AddRow appends a row. Values beyond the column count are silently ignored; missing values are treated as empty strings.

func (*Table) Render

func (t *Table) Render(w io.Writer) error

Render writes the table to w with computed column widths.

Jump to

Keyboard shortcuts

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