diag

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package diag defines build diagnostics: a stable, file:line-addressed description of every problem found while loading or building a site.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(d Diagnostic) string

Format renders d as "file:line:col: severity[code]: message". The line and column are omitted when unknown, and the file part is omitted when the diagnostic is not tied to a file.

func HasErrors

func HasErrors(ds []Diagnostic) bool

HasErrors reports whether any diagnostic in ds is error-level.

func Sort

func Sort(ds []Diagnostic)

Sort orders diagnostics by file, line and column. It is stable, so diagnostics at the same position keep their insertion order.

Types

type Collector

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

Collector gathers diagnostics. It is safe for concurrent use.

func (*Collector) Add

func (c *Collector) Add(ds ...Diagnostic)

Add records diagnostics.

func (*Collector) All

func (c *Collector) All() []Diagnostic

All returns a sorted copy of the collected diagnostics.

func (*Collector) Count

func (c *Collector) Count(sev Severity) int

Count returns the number of diagnostics with the given severity.

func (*Collector) Errorf

func (c *Collector) Errorf(file string, line, col int, code, format string, args ...any)

Errorf records an error-level diagnostic.

func (*Collector) HasErrors

func (c *Collector) HasErrors() bool

HasErrors reports whether any error-level diagnostic was collected.

func (*Collector) Infof

func (c *Collector) Infof(file string, line, col int, code, format string, args ...any)

Infof records an info-level diagnostic.

func (*Collector) Len

func (c *Collector) Len() int

Len returns the number of collected diagnostics.

func (*Collector) Warnf

func (c *Collector) Warnf(file string, line, col int, code, format string, args ...any)

Warnf records a warning-level diagnostic.

type Diagnostic

type Diagnostic struct {
	Severity Severity
	File     string // relative to project root
	Line     int    // 1-based; 0 if unknown
	Col      int    // 1-based; 0 if unknown
	Code     string // stable id, e.g. "frontmatter.yaml", "link.broken"
	Message  string
}

Diagnostic is a single problem report.

func (Diagnostic) String

func (d Diagnostic) String() string

type Severity

type Severity int

Severity orders diagnostics from least to most serious.

const (
	Info Severity = iota
	Warning
	Error
)

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

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