metrics

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatValue

func FormatValue(def Definition, value Value) string

FormatValue renders a metric value for text output.

func JSONValue

func JSONValue(def Definition, value Value) any

JSONValue converts a metric value into a JSON-safe scalar. Unavailable values return nil.

func LookupDoc

func LookupDoc(query string) (string, error)

LookupDoc finds a metric doc by ID (e.g. MET001) or name (e.g. bytes) and returns its README content with front matter stripped.

func SortRows

func SortRows(rows []Row, by Definition, order Order)

SortRows sorts rows deterministically by a metric and path tiebreaker.

func SplitList

func SplitList(raw string) []string

SplitList parses comma-separated metric names.

Types

type Definition

type Definition struct {
	ID           string
	Name         string
	Description  string
	Scope        Scope
	Kind         ValueKind
	Precision    int
	Default      bool
	DefaultOrder Order
	Compute      func(doc *Document) (Value, error)
}

Definition describes a metric and how to compute it.

func All

func All() []Definition

All returns all metrics sorted by ID.

func Defaults

func Defaults(scope Scope) []Definition

Defaults returns default-selected metrics for a scope.

func ForScope

func ForScope(scope Scope) []Definition

ForScope returns all metrics for a scope, sorted by ID.

func Lookup

func Lookup(query string) (Definition, bool)

Lookup searches by metric ID (case-insensitive) or by name.

func LookupScope

func LookupScope(scope Scope, query string) (Definition, bool)

LookupScope searches by metric ID (case-insensitive) or name within scope.

func Resolve

func Resolve(scope Scope, names []string) ([]Definition, error)

Resolve resolves user-selected metric names/IDs for a scope. Empty names returns default metrics.

type DocInfo

type DocInfo struct {
	ID          string
	Name        string
	Description string
	Content     string
}

DocInfo holds metadata extracted from a metric README's front matter.

func ListDocs

func ListDocs() ([]DocInfo, error)

ListDocs returns all embedded metrics docs sorted by ID.

type Document

type Document struct {
	Path   string
	Source []byte
	// contains filtered or unexported fields
}

Document is the shared metric input for a single Markdown file. Expensive derived values are computed lazily and cached.

func NewDocument

func NewDocument(path string, source []byte) *Document

NewDocument constructs a Document wrapper for metric computation.

func (*Document) ByteCount

func (d *Document) ByteCount() int

ByteCount returns raw file byte count.

func (*Document) File

func (d *Document) File() (*lint.File, error)

File returns the parsed Markdown file.

func (*Document) HeadingCount

func (d *Document) HeadingCount() (int, error)

HeadingCount returns number of heading nodes.

func (*Document) LineCount

func (d *Document) LineCount() int

LineCount returns content line count.

func (*Document) PlainText

func (d *Document) PlainText() (string, error)

PlainText returns plain text extracted from the Markdown AST.

func (*Document) WordCount

func (d *Document) WordCount() (int, error)

WordCount returns word count on extracted plain text.

type Order

type Order string

Order defines metric sort order.

const (
	// OrderAsc sorts from smallest to largest.
	OrderAsc Order = "asc"
	// OrderDesc sorts from largest to smallest.
	OrderDesc Order = "desc"
)

func ParseOrder

func ParseOrder(raw string) (Order, error)

ParseOrder parses a user-provided sort order.

type Row

type Row struct {
	Path    string
	Metrics map[string]Value
}

Row holds computed metric values for a single file.

func Collect

func Collect(paths []string, defs []Definition, maxBytes int64) ([]Row, error)

Collect computes all selected metrics for each file path. maxBytes limits the file size that will be read; zero or negative means unlimited.

func LimitRows

func LimitRows(rows []Row, top int) []Row

LimitRows returns at most top rows (if top > 0).

type Scope

type Scope string

Scope defines the entity level a metric applies to.

const (
	// ScopeFile indicates a file-level metric.
	ScopeFile Scope = "file"
)

func ParseScope

func ParseScope(raw string) (Scope, error)

ParseScope parses a user-provided scope value.

type Value

type Value struct {
	Number    float64
	Available bool
}

Value is a computed numeric metric value.

func AvailableValue

func AvailableValue(n float64) Value

AvailableValue constructs an available metric value.

func UnavailableValue

func UnavailableValue() Value

UnavailableValue constructs an unavailable metric value.

type ValueKind

type ValueKind string

ValueKind describes how to render a numeric metric value.

const (
	// KindInteger renders values as rounded integers.
	KindInteger ValueKind = "integer"
	// KindFloat renders values with fixed decimal precision.
	KindFloat ValueKind = "float"
)

Jump to

Keyboard shortcuts

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