Documentation
¶
Overview ¶
Package config loads .formwork/ YAML strictly and compiles rule envelopes into executable rules (spec §5). Any schema error is fatal — never a silent skip.
scan.go — the formwork.yaml `scan:` block: the two repo-global channels that remove paths from the shared walk before any rule sees them, and their load-time validation. Split from config.go, which the 750-line vendor cap bounds; same package.
scopeparse.go — the parsers for the rule `scope:` block. Split from config.go, which the 750-line vendor cap bounds; same package.
Index ¶
- type Allowlist
- type AllowlistEntry
- type Config
- type Envelope
- type ExcludeEntry
- type GitignoreEntry
- type IgnoreEntry
- type Lane
- type LangClass
- type Rule
- func (r *Rule) Applies(relPath string) bool
- func (r *Rule) CarvedOutBy(relPath string) (string, bool)
- func (r *Rule) CloneWithChecker(c rules.Checker) *Rule
- func (r *Rule) Cost() rules.Cost
- func (r *Rule) Exclude() []string
- func (r *Rule) ExcludeEntries() []ExcludeEntry
- func (r *Rule) Fresh() (*Rule, error)
- func (r *Rule) Include() []string
- func (r *Rule) MinFiles() int
- func (r *Rule) Params() (any, error)
- func (r *Rule) ParamsYAML() (string, error)
- func (r *Rule) SetMinFiles(n int) error
- func (r *Rule) WholeTreeInvariant() bool
- type ScopeConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Allowlist ¶
type Allowlist struct {
File string // as configured, relative to .formwork/
Entries []AllowlistEntry
}
Allowlist is a loaded exemption file: exact repo-relative paths whose findings for the owning rule are suppressed (phase-3a design §3).
type AllowlistEntry ¶
AllowlistEntry is one path plus its 1-based line in the allowlist file (used by lint staleness messages).
type Config ¶
type Config struct {
Version int
// Engine is the raw engine-version constraint from formwork.yaml ("" if
// absent). EngineConstraint is its parsed form (nil if absent). A binary
// whose version does not satisfy the constraint refuses to run (spec §4).
Engine string
EngineConstraint *semver.Constraints
Lanes []Lane
Scope ScopeConfig
Ignore []IgnoreEntry
// Gitignore is the scan.gitignore declaration, nil when the key is absent.
// Absent is off: a repo that does not declare it gets exactly the walk it
// got before this key existed.
Gitignore *GitignoreEntry
Rules []*Rule
// RuleFiles is how many .formwork/rules/*.yaml files were read, whatever
// they declared. It exists so a zero-rule refusal can name the actual
// cause: no rule files at all is a different mistake from rule files that
// parse and declare nothing (an empty or null `rules:` list, the shape a
// bad merge or a templating error produces), and "add a rule file" is
// useless advice to someone staring at the rule file they just wrote.
RuleFiles int
}
Config is the loaded, compiled configuration. Rules are sorted by ID and Lanes by Name.
func Load ¶
Load reads .formwork/formwork.yaml and .formwork/rules/*.yaml under repoRoot and returns compiled rules sorted by ID. A thin wrapper over ReadEnvelope + LoadRules for callers (and tests) that have no gate to run in between and so don't need the two steps split apart.
func (*Config) IgnoreGlobs ¶
IgnoreGlobs returns the glob half of every scan.ignore entry, in config order. This is what scan.WalkIgnoring consumes; lint keeps the full entries for the census.
type Envelope ¶
type Envelope struct {
Version int
Engine string
EngineConstraint *semver.Constraints
// contains filtered or unexported fields
}
Envelope is a read-once .formwork/formwork.yaml: the raw bytes are read and parsed exactly once, so a caller that needs to gate on it (the engine-version backstop, spec §4) before parsing any rule file is guaranteed to gate on the very same bytes LoadRules subsequently compiles — not a possibly-different later read of the file (finding 8: the file used to be read once for the gate via LoadRootMeta and a second time for execution via Load, so the gate's guarantee weakened from "allowed to evaluate THIS config" to "was allowed to evaluate some recent config").
func ReadEnvelope ¶
ReadEnvelope reads and validates ONLY .formwork/formwork.yaml, once. The caller gates on the envelope (engine constraint) before calling LoadRules, so an unsupported binary reports its version rather than failing on rule schema it was never built to understand.
type ExcludeEntry ¶
ExcludeEntry is one scope.exclude glob plus its optional YAML justification comment (empty when the entry had none).
type GitignoreEntry ¶
type GitignoreEntry struct {
Reason string
}
GitignoreEntry is the scan.gitignore declaration: a standing instruction to prune every path git itself refuses to track.
There is deliberately NO boolean here. A `prune: false` spelling would add a third state — declared but inert — that reads at a glance like the channel is active, and this is the widest exemption channel in the engine; the only way to turn it off is to delete the block, which no reader can misread.
Reason is required by schema (exit 2 without it) for the same purpose it is required on IgnoreEntry: this hides paths from every FileSet-consuming rule at once, and a channel that wide must say in the config why it exists, rather than relying on a lint check that might not run.
type IgnoreEntry ¶
IgnoreEntry is one scan.ignore glob plus its mandatory justification. scan.ignore hides matching paths from every FileSet-consuming rule in the run — the widest exemption channel in the engine — which is why Reason is required by schema (exit 2 without it) rather than by a lint check that might not run. External-tool rules (command, git-diff) shell out and rescan on their own, so they can still SEE ignored trees: extra findings, never silently missed ones (spec §5).
type Lane ¶
type Lane struct {
Name string
All bool
Tags []string
Cost string // "", "fast", or "heavy"
CI bool
}
Lane is an orchestration group: a named selector over rules (spec §8). Exactly one of All or Tags is set (validated at load). Cost, when set, further restricts the lane to rules of that cost class ("" = any cost). CI reports whether the lane runs in CI — lint's lane-reachability check (spec §9) requires every rule to be selected by at least one CI lane.
type Rule ¶
type Rule struct {
ID string
Type string
Severity finding.Severity
Cure string
Origin string
Tags []string
Checker rules.Checker
// FixtureExempt is a heavy rule's declared reason for carrying no fixtures
// (#53). Empty means undeclared, which lint reports rather than skips.
FixtureExempt string
Preprocess string // preprocess variant name; "" means raw
Marker bool // honor inline formwork:allow markers
Allowlist *Allowlist // loaded except.allowlist, nil when absent
ExceptPaths []string // except.paths carve-out globs (read-only after construction)
// contains filtered or unexported fields
}
Rule is a compiled rule: envelope plus instantiated checker.
func New ¶
func New(id, typeName string, sev finding.Severity, cure string, include, exclude, exceptPaths []string, c rules.Checker) (*Rule, error)
New builds a compiled rule directly. Load uses it; engine and report tests use it to construct rules without YAML.
func (*Rule) CarvedOutBy ¶
CarvedOutBy reports which except.paths glob removed relPath from this rule's evaluation, and whether any did.
The include/exclude test comes FIRST and is the whole point: a path the rule never covered was not carved out by anything, so a count built on this measures a carve-out's EFFECT rather than its declaration (#138). That is the same distinction scan.ignore already reports with live match counts, and the one except.paths was missing — an entry whose subject moved away printed with the same weight as one doing real work.
except.paths is a scope SUBTRACTION, not a suppression: Applies returns false for a matched path, so the rule never evaluates the file and there is no finding for a census to count. Reading the file set is the only way to see it.
func (*Rule) CloneWithChecker ¶
CloneWithChecker returns a shallow copy of the rule with its checker replaced. Used by lint's load-bearing-prefilter differential to evaluate a prefilter-stripped variant of a rule. The clone shares the scope slices, params node, and allowlist with the original; all are read-only after construction, so sharing is safe (mirrors Fresh).
func (*Rule) Cost ¶
Cost is the rule's evaluation cost class, defaulting to fast for checkers that do not declare one (spec §8).
func (*Rule) Exclude ¶
Exclude returns this rule's scope.exclude globs (read-only; do not mutate). Empty when the rule has no excludes. Used by formwork lint's escape-hatch census and dead-exclude hygiene.
func (*Rule) ExcludeEntries ¶
func (r *Rule) ExcludeEntries() []ExcludeEntry
ExcludeEntries returns each scope.exclude glob paired with its YAML justification comment (empty string when the entry had none).
func (*Rule) Fresh ¶
Fresh returns a copy of the rule with a newly constructed checker. Checkers may carry per-run state (e.g. required-pattern exists mode), so evaluating a rule against multiple independent trees — as the fixture runner does — requires a fresh instance per tree. Rules built with New (no factory) cannot be refreshed. The clone is shallow and shares the scope slices and params node with the original; this is safe because both are treated as read-only after construction.
func (*Rule) Include ¶
Include returns this rule's scope.include globs (read-only; do not mutate). Introspection surface (#105/#108): explain and rules-for render scope from the same globs Applies consults, so the display can never drift from the verdict.
func (*Rule) MinFiles ¶
MinFiles returns this rule's scope floor: the number of files its scope must select before the rule is considered to have had anything to look at. Zero — the default for every rule that does not declare `scope.min_files` — means no floor, which is exactly the behaviour that shipped before the key existed.
func (*Rule) Params ¶
Params returns the rule's retained params decoded into plain Go values (maps/slices/scalars), or nil when the rule declared none. Introspection only — the checker was compiled from this same node at load time, so this is a rendering of what already governs, never a second source of truth.
func (*Rule) ParamsYAML ¶
ParamsYAML re-renders the retained params node as YAML for human display, or "" when the rule declared none.
func (*Rule) SetMinFiles ¶
SetMinFiles sets the scope floor, refusing a value that could never fire.
The field is unexported and this is the only door onto it, so compile (the YAML path) and the New-plus-setter path used by tests cannot disagree about what a legal floor is. A negative floor is refused rather than clamped: every possible file count satisfies it, so it would read as armed while being incapable of failing.
func (*Rule) WholeTreeInvariant ¶
WholeTreeInvariant reports whether the rule's verdict is a whole-repo invariant that must be evaluated over the whole tree even under a --staged/--range changeset scan (mirrors Cost). Range-scoping a required- pattern(exists) / set-relation / pattern-count / baseline rule false-fails it when the file bearing its token is not in the change range (#4).
type ScopeConfig ¶
type ScopeConfig struct {
Docs []string
Governance []string
Languages []LangClass // sorted by Name for deterministic output
}
ScopeConfig classifies a changeset (spec §8): which paths are docs, governance, or (by default) runtime, plus per-language change globs.
func (ScopeConfig) Classify ¶
func (sc ScopeConfig) Classify(changed []string) (class string, langs map[string]bool)
Classify returns the changeset's class and per-language change flags. A file matching no docs/governance glob is runtime (fail-closed, spec §11); the changeset takes the highest class of any file (runtime > governance > docs). An empty changeset is docs (nothing to gate).