corpus

package
v0.17.10 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 21 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 corpus is the public API for analysing a formwork rule corpus.

WHY THIS EXISTS. A tool that asks questions ABOUT a corpus — can this rule ever fail, does this rule still fire, does this arm match anything — has to measure scope with the SAME scanner and matcher the gate engine runs. Re-implementing doublestar matching is not a shortcut, it is the known way to get a wrong answer: a downstream census that did so reported "133 of 200 rules match zero files", and every one of those was an artefact of the re-implementation.

Those parts live under internal/, so Go admits only importers whose module path sits under this module's. Downstream analysers reached them by declaring module paths like github.com/buildfoundry-nz/formwork/vacuitycensus from a different repository entirely — Go's internal rule keys on the import-path prefix, so a module can grant itself access by naming itself into another module's path. Three such modules, some 8,000 lines, depend on that today.

That arrangement works only because Go checks a string prefix rather than actual module membership, and it is invisible from here: a rename under internal/ breaks a build in a repository this one has never heard of. This package replaces the workaround with a supported surface, so an analyser can be an ordinary consumer of a published module (buildfoundry-nz/formwork#5).

The types are aliases, not wrappers. A *Rule obtained here IS the engine's rule, so nothing is lost across the boundary and there is no conversion cost.

Index

Constants

View Source
const CostHeavy = rules.CostHeavy

CostHeavy marks a checker that shells out or is otherwise expensive.

View Source
const SeverityError = finding.SeverityError

SeverityError is the severity that fails a gate.

Variables

This section is empty.

Functions

func UnderBuiltinSkip

func UnderBuiltinSkip(path string) bool

UnderBuiltinSkip reports whether a path sits under a directory the engine always skips. An analyser that does not ask will count files the gate cannot see, and report a rule as covering them.

Types

type AnchorProbe

type AnchorProbe = rules.AnchorProbe

AnchorProbe is the fail-closed half of a NAME-anchored rule type.

type Checker

type Checker = rules.Checker

Checker is a constructed rule type.

type Config

type Config = config.Config

Config is a loaded .formwork/ corpus.

func Load

func Load(repoRoot string) (*Config, error)

Load reads and validates the corpus under repoRoot/.formwork.

type Cost

type Cost = rules.Cost

Cost says how expensive a checker is to run.

func CostOf

func CostOf(c Checker) Cost

CostOf reports a checker's cost.

type Factory

type Factory = rules.Factory

Factory builds a Checker from a rule's params.

func Lookup

func Lookup(name string) (Factory, bool)

Lookup resolves a rule type name to its factory. Reports false for a name no built-in registers — which, because this package registers them all, means the name is genuinely unknown rather than merely unimported.

type File

type File = scan.File

File is one scanned file.

func NewMemFile

func NewMemFile(relPath string, content []byte) *File

NewMemFile makes an in-memory file, for probing a rule without touching disk.

type FileSet

type FileSet = scan.FileSet

FileSet is a whole scanned tree.

func Walk

func Walk(root string) (*FileSet, error)

Walk scans a tree the way the engine does.

type Finding

type Finding = finding.Finding

Finding is one rule violation.

func Run

func Run(rls []*Rule, fset *FileSet, workers int) ([]Finding, error)

Run evaluates rules over a file set, as the gate does.

type Rule

type Rule = config.Rule

Rule is one rule, exactly as the engine evaluates it.

func New

func New(id, typeName string, sev Severity, cure string, include, exclude []string, c Checker) (*Rule, error)

New builds a rule in memory, for analysers that synthesise one to probe with.

type Severity

type Severity = finding.Severity

Severity is a finding's severity.

Jump to

Keyboard shortcuts

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