lint

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package lint checks a spec repository against the rules in PROCESS.md. Every rule is a function returning findings; nothing here prints or exits.

Index

Constants

This section is empty.

Variables

View Source
var Rules = []Rule{
	{"L01", L01},
	{"L02", L02},
	{"L03", L03},
	{"L04", L04},
	{"L05", L05},
	{"L06", L06},
	{"L07", L07},
	{"L08", L08},
	{"L09", L09},
	{"L10", L10},
	{"L11", L11},
	{"L12", L12},
	{"L13", L13},
	{"L14", L14},
	{"L15", L15},
	{"L16", L16},
	{"L17", L17},
	{"L18", L18},
}

Rules is every rule, in code order.

Functions

This section is empty.

Types

type BranchFile

type BranchFile struct {
	Content []byte
	Status  repo.Status
	Err     error
}

BranchFile is a document as it stands on the branch. Err records a failure to read it, which must not be mistaken for the document being new: one means the repository is unreadable, the other that the document is editable.

type Context

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

Context is everything a rule needs.

Its fields are unexported and NewContext is the only way to fill them. That is deliberate: the branch snapshot is what Frozen reads, and a Context built as a literal without it reported every document as editable, which made the same document an error from one command and a warning from another. A rule stating "use the constructor" in a comment was not enough, so the compiler states it instead.

func NewContext

func NewContext(r *repo.Repo, g git.Repository, now time.Time) Context

NewContext builds a Context with the branch snapshot populated. Any caller whose rules depend on whether a document is frozen must use this rather than building a Context literal: Branch is what Frozen reads, and a Context without it reports every document as editable.

func (Context) Frozen

func (c Context) Frozen(d *repo.Document) bool

Frozen reports whether a document has already reached the branch in a terminal status, and so can no longer be edited. A rule never reports an error against a frozen document, because L11 forbids the fix.

func (Context) Git

func (c Context) Git() git.Repository

Git is the repository's git, or nil when there is not one.

func (Context) Now

func (c Context) Now() time.Time

Now is the date the rules compare against.

func (Context) OnBranch

func (c Context) OnBranch(path string) (BranchFile, bool)

OnBranch is a document as it stands on the configured branch. ok is false when it is new there, or when there is no branch to compare against.

func (Context) Repo

func (c Context) Repo() *repo.Repo

Repo is the repository being checked.

type Finding

type Finding struct {
	// Path is relative to root.
	Path string
	// Line is 1-based, or 0 when the finding has no single line.
	Line     int
	Severity Severity
	Message  string
	Rule     string
}

Finding is one rule's complaint about one place.

func L01

func L01(ctx Context) []Finding

L01 checks that front matter parses and matches the schema for the type.

func L02

func L02(ctx Context) []Finding

L02 checks that the identifier matches the type and filename, and that the filename has the required shape.

func L03

func L03(ctx Context) []Finding

L03 checks that no identifier appears on more than one document.

func L04

func L04(ctx Context) []Finding

L04 checks that every reference resolves to an existing document of a type the field permits.

func L05

func L05(ctx Context) []Finding

L05 checks updates and obsoletes: same type, accepted, not the document itself, and not both at once.

func L06

func L06(ctx Context) []Finding

L06 checks that a spec page includes only accepted documents.

func L07

func L07(ctx Context) []Finding

L07 checks decided against the status and the created date.

func L08

func L08(ctx Context) []Finding

L08 checks that the required sections are present, correctly titled and in the required relative order, and that Rejection rationale is present exactly when the document is rejected.

func L09

func L09(ctx Context) []Finding

L09 checks that an accepted document leaves no open questions. Keyed on the section being present rather than on the document type, so it still holds if an ADR carries one as an extra section.

func L10

func L10(ctx Context) []Finding

L10 checks the H1 against the front matter.

func L11

func L11(ctx Context) []Finding

L11 checks that a frozen document is unchanged. A document is frozen once it has reached the branch in a terminal status; until then the working tree may differ freely, which is what makes the freezing commit legal.

func L12

func L12(ctx Context) []Finding

L12 checks that a spec page includes nothing that is effectively obsolete. Obsolescence claimed by a document that is not accepted has no effect, so a page is stale only once the replacement has actually been decided.

func L13

func L13(ctx Context) []Finding

L13 checks that a ref has been verified recently enough. A ref_stale_days of zero disables the rule.

func L14

func L14(ctx Context) []Finding

L14 checks that no required section was left empty. It does not apply to withdrawn documents, whose sections are empty by the nature of abandonment, and it exempts the two sections that are legitimately empty: Open questions, which L09 requires to be empty before acceptance, and Changelog, which stays empty for a document never edited while proposed.

func L15

func L15(ctx Context) []Finding

L15 checks the glossary: unique terms, in ascending case-insensitive order, one paragraph each.

func L16

func L16(ctx Context) []Finding

L16 checks that no [[...]] wiki link is left unexpanded.

func L17

func L17(ctx Context) []Finding

L17 checks that every relative link resolves to a file, and to a heading when it carries an anchor.

func L18

func L18(ctx Context) []Finding

L18 checks that a document does not rest on something less settled than itself. Two proposed documents may depend on one another, but an accepted document resting on a draft is suspicious.

func Run

func Run(ctx Context) []Finding

Run applies every rule and returns the findings, ordered by path, then line, then rule, so that output is stable between runs.

type Rule

type Rule struct {
	Code  string
	Check func(Context) []Finding
}

Rule is one check, identified by the code it reports under.

type Severity

type Severity string

Severity is how much a finding matters. A rule never reports an error against a frozen document, because L11 forbids the edit that would clear it.

const (
	Error   Severity = "error"
	Warning Severity = "warning"
)

Jump to

Keyboard shortcuts

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