check

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package check runs the audit rules of spec 15.3 that `prog check` needs.

Each rule has an id, such as T01. A rule with the severity "block" stops a merge. A rule with the severity "level" keeps a part below the level that needs it. A rule with the severity "warn" only reports.

Index

Constants

This section is empty.

Variables

View Source
var Filled = map[string]bool{"References": true, "In languages": true, "The guide": true, "Versions": true, "Versions and support": true, "Comparison": true, "Support dates": true, "Alternatives": true, "Implementations": true}

Filled are the sections that the build fills. An empty heading only marks the place.

View Source
var Order = func() map[string][]string {
	out := map[string][]string{}
	for _, k := range node.KindList {
		for _, s := range k.Sections {
			out[k.ID] = append(out[k.ID], s.Name)
		}
	}
	return out
}()

Order lists the headings of each kind in their order (spec 06.3).

View Source
var Rules = map[string]string{
	"T01": "node.md front matter is valid for its kind, and an owned kind names its owner",
	"T02": "each tag is in registers/tags.reg, once, with its slug",
	"T03": "each slug is unique, has the form of its kind, and is not an old slug in aliases.reg",
	"T04": "the path of the node matches its area",
	"T05": "no status, level or badge is written in front matter",
	"T06": "no provisional id is left on main",
	"G01": "prereqs edges form a DAG",
	"G02": "variant_of and generalizes edges have no cycle",
	"G03": "each solves target is a problem node",
	"G04": "each implements target is an abstract type",
	"G05": "each edge target exists",
	"G07": "no edge points to its own node; see_also has at most 8 targets",
	"E01": "each complexity string parses",
	"E04": "each variable of a claim is defined in vars, and the model exists",
	"W01": "the section headings of the kind are in order",
	"W03": "pseudocode line ids are unique, and each @line marker names an existing id",
	"I10": "each implementation and test file starts with the SPDX header",
	"I11": "each line id of the main pseudocode has a marker in each tier-1 implementation",
	"I12": "each implementation language is in the register",
	"I15": "no generated file under build/ is committed, and no implementation has a build file; prog gen writes them",
	"S01": "contract.yaml is valid; each complexity variable of each solving algorithm is a size parameter or is defined",
	"S02": "each case validates against the contract",
	"S03": "a custom checker has checker cases, valid and invalid, with a note for each invalid output",
	"S04": "edge.jsonl has at least one case for each class of edge_classes",
	"S05": "each generator is a Python file under generators/ that uses only the rng it gets",
	"S06": "the contract of each core problem is reviewed by a person, bound to its hash",
	"S08": "mutants.ignore of an implementation lists at most 5% of its mutants, each with a reason, and each entry names a mutant of the sample",
	"S09": "a flaky case names its open issue",
	"L01": "each Lean name in the front matter exists in decls.jsonl with the expected kind",
	"L02": "the correctness theorem mentions the spec and the model",
	"L03": "each declaration uses only propext, Classical.choice and Quot.sound",
	"L04": "the fidelity review of the spec of a core node is current",
	"L05": "each time claim of a node with lean.cost has a class lemma of the same class",
	"L07": "the model is total and computable",
	"L09": "the module path mirrors the node path",
	"L10": "each module builds in at most 60 seconds; prog lean build -time reports it, and a module above 300 seconds blocks",
	"X01": "each link in a node to /<slug>/ or /<owner>/<slug>/ names a node, an area or a site page",
	"X06": "no node slug is a reserved word, a language id or an area id",
}

Rules lists the rules that this package runs, with their text.

Functions

func Markers

func Markers(content string) []string

Markers returns the line ids that the @line markers of a file name.

func ParseClaim

func ParseClaim(s string) error

ParseClaim checks one complexity string in the small grammar of spec 04.4.

A claim is a bound, Θ(e), O(e), Ω(e), o(e) or ω(e), or an exact expression e. Words such as "amortized", "expected" and "w.h.p." may follow. An expression uses numbers, variables, the functions log, lg, ln, sqrt, min, max, the operators + − - * · × / ^, brackets ( ) ⌊ ⌋ ⌈ ⌉ and |x|.

func Vars

func Vars(s string) []string

Vars returns the variables of a claim, once each, in order.

Types

type Finding

type Finding struct {
	Rule     string   `json:"rule"`
	Severity Severity `json:"severity"`
	Path     string   `json:"path"`
	Line     int      `json:"line,omitempty"`
	Msg      string   `json:"msg"`
}

Finding is one result of a rule.

func PseudoIDs

func PseudoIDs(body string) (map[string][]string, []Finding)

PseudoIDs returns the line ids of the pseudocode blocks of a body, by block id. A block with no id is "main".

func Run

func Run(c *node.Corpus, opt Options) []Finding

Run runs the rules on the corpus and returns the findings, sorted by path and line.

func (Finding) String

func (f Finding) String() string

type Options

type Options struct {
	// Only, when not empty, limits the run to these slugs.
	Only map[string]bool
	// Rule, when not empty, runs only this rule.
	Rule string
	// Main is true on the main branch, where provisional ids are an error (T06).
	Main bool
	// Decls are the declarations that prog lean build wrote. When it is nil, the rules L01 to L09 that need them do not run.
	Decls formal.Decls
	// Checker, when it is not nil, starts the custom checker of a contract. S03 then runs the checker on each line of checker_cases.jsonl. The caller decides where the checker runs, such as in the sandbox.
	Checker func(k *contract.Contract) (*contract.Custom, error)
}

Options select what to check.

type Severity

type Severity string

Severity is how much a finding matters.

const (
	Block Severity = "block"
	Level Severity = "level"
	Warn  Severity = "warn"
)

Jump to

Keyboard shortcuts

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