Documentation
¶
Overview ¶
Package diag defines build diagnostics: a stable, file:line-addressed description of every problem found while loading or building a site.
Index ¶
- func Format(d Diagnostic) string
- func HasErrors(ds []Diagnostic) bool
- func Sort(ds []Diagnostic)
- type Collector
- func (c *Collector) Add(ds ...Diagnostic)
- func (c *Collector) All() []Diagnostic
- func (c *Collector) Count(sev Severity) int
- func (c *Collector) Errorf(file string, line, col int, code, format string, args ...any)
- func (c *Collector) HasErrors() bool
- func (c *Collector) Infof(file string, line, col int, code, format string, args ...any)
- func (c *Collector) Len() int
- func (c *Collector) Warnf(file string, line, col int, code, format string, args ...any)
- type Diagnostic
- type Severity
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) All ¶
func (c *Collector) All() []Diagnostic
All returns a sorted copy of the collected diagnostics.
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