meta

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 23 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

census.go — the escape-hatch enumeration (spec §9). Split from lint.go, which the 750-line vendor cap bounds; same package.

credentials.go — dead-entry hygiene for require_absent credentials. Split from lint.go, which the 750-line vendor cap bounds; same package.

A credential no in-scope line holds sanctions nothing. The check used to report that as a holder count of zero, which also fired on every pruned or synthetic tree that carries one rule beside only the files its own proof needs: such a tree holds none of the repository's homes, and a check cannot tell that from a home that is gone. The zero case is judged here instead, over the whole tree, as notDeclaringProblems judges a marker no file declares, so a dead credential still fails `formwork lint` while a scratch tree still runs `formwork check`.

Package meta implements formwork lint: self-integrity checks over the configuration itself (spec §9). Phase 2 delivered fixture-coverage and empty-scope; phase 3a adds exemption-hygiene and the escape-hatch enumeration.

lintpolicy.go — the corpus-selectable check set (#89). Split from lint.go, which the 750-line vendor cap bounds; same package.

notdeclaring.go — dead-entry hygiene for scope.not_declaring. Split from lint.go, which the 750-line vendor cap bounds; same package.

A marker no file in the rule's scope declares subtracts nothing, and that is the failure mode which makes an exemption dangerous rather than merely useless: it reads as a narrow, reasoned carve-out while protecting nothing, so a reader stops looking for the real one.

No comment escape here, unlike scope.exclude. A preventative glob for a directory the repo has not created yet is a coherent thing to write; a marker for a declaration no generator emits is a guess, and its cure is to name a marker some generator actually writes.

parentsegment.go — `formwork lint`'s command-argv-no-parent-segment check (#28).

A command rule that names its tree with a path relative to the caller's working directory is read differently on every plane the engine evaluates. `--root ../../..` means the repository under `check`, where the working directory is the repository; under `test` the fixture runner makes the fixture tree the working directory and the same three segments climb back out into the repository, so the fixture judges the real tree. {{root}} and {{repo}} say it once and the engine resolves them per plane.

WHY LINT AND NOT A LOAD REFUSAL. Refusing at load is the stronger shape and was the first one tried: a rule that does not load cannot read the wrong tree even once. It also makes every corpus written before the tokens unreadable — and the tools that read an old corpus are the ones that most need to. The vacuity census loads the corpus as it stood at a change's merge base, to tell a rule this change ADDED from one it merely edited; a base it cannot parse is a transition it cannot compute, and its own comment says an unparseable base must never resolve to "nothing changed". A load refusal therefore broke the census for every branch cut before the migration, and for any commit older than it.

Lint runs on every pull request, so the shape still cannot merge. What it no longer does is make history unreadable.

scope.go — the shared "what did this rule have to look at" predicate, and the prune-channel counts. Split from lint.go, which the 750-line vendor cap bounds; same package.

subject.go — scope.subject: production in the escape-hatch census and its dead-entry hygiene. Split from census.go and lint.go, which the 750-line vendor cap bounds; same package.

A production subject leaves the repository's test code out of the rule (config/testcode.go). That is a statement about what the rule is about, not a forgiven violation, but it still removes files from evaluation, so the census counts them on every run and lint refuses a statement that removes nothing.

trigger.go — the command-trigger-armable check (#161). Split from lint.go, which the 750-line vendor cap bounds; same package.

unreadable.go — lint's refusal to judge a tree it cannot read (#30). Split from lint.go, which the 750-line vendor cap bounds; same package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyScopeFloor

func AnyScopeFloor(rls []*config.Rule) bool

AnyScopeFloor reports whether any of these rules arms a scope floor. It is the cheap question `check` asks before paying for a tracked-tree listing in a file-set run: a corpus that declared no floor must not acquire a git call on the pre-commit path for a feature it does not use.

func AnySupersetUnsafe

func AnySupersetUnsafe(rls []*config.Rule) bool

AnySupersetUnsafe reports whether any rule cannot be judged over a scan that pruned LESS than declared (#178).

When scan.gitignore is declared and git cannot answer, nothing is pruned and the tree scanned is a superset of the declared one. That was argued fail-closed, and for most rules it is: a rule firing on the PRESENCE of something can only gain matches from a superset, never lose one.

The argument inverts for a rule that fires on an ABSENCE. A superset can supply the very thing whose absence was the violation, and the finding disappears — over a scan the operator was told was larger, not smaller. A scope floor was the first member found (a floor is a claim about the declared corpus that an unpruned tree can satisfy); it is not the only one.

The population is exactly rules.IsWholeTreeInvariant: a verdict that depends on the whole scanned set is precisely what a superset breaks. Asked as a property rather than a list of rule types, because a list would need maintaining and the next absence-asserting type would be added without it.

One-sided in the safe direction. It includes whole-tree invariants whose verdict a superset could not actually erase, and refusing there costs a diagnosable exit 2 rather than a silent wrong answer.

func GitIgnoredSet

func GitIgnoredSet(recs []vcs.IgnoredPath) *scan.GitIgnored

GitIgnoredSet keys confirmed-ignored records for the walk. This is the ONE construction of a prune set from vcs records — the walk snapshot and rules-for's ghost frame both build through it, so a future filter or key normalization cannot be applied to one and silently missed by the other (#125 round-2 finding 5).

func Lint

func Lint(cfg *config.Config, root string, w io.Writer, devOptOutActive bool, scoped bool) (int, error)

Lint runs the self-integrity checks against root's config and tree, writes per-check verdicts plus the escape-hatch enumeration to w, and returns how many checks failed. devOptOutActive reports whether FORMWORK_ALLOW_DEV is actually letting the RUNNING binary skip a declared engine constraint — the gate version that fact depends on lives in package cli, which imports this package, so the caller computes it and passes it in rather than this package importing cli back (that would be a cycle).

func PruneChannels

func PruneChannels(cfg *config.Config, ignored []scan.Ignored, gi GitIgnoreResult) []report.PruneChannel

PruneChannels enumerates the declared prune channels with live counts, in config order (every scan.ignore glob, then scan.gitignore). Both `check`'s scan summary and `lint`'s escape-hatch enumeration render these, so a typo'd glob reports "0 matches" from both rather than silently protecting nothing in one of them.

Only the two DECLARED channels appear, because a channel here is built per config entry and those are the only two an operator declares. Built-in skips are pruned without a record, and scope.exclude/except.paths are rule fields the scan package never sees — so this is a census of what the operator declared, never of everything the walk withheld.

A symlink the walk declined to follow IS recorded (#235) and still does not belong here: it is declared nowhere, so there is no glob and no reason to key a channel on. UnfollowedLinks below is its peer, and both are rendered by `check` and `lint` alike.

func RulesMatchingNoFiles

func RulesMatchingNoFiles(rls []*config.Rule, files []*scan.File) []string

RulesMatchingNoFiles returns the ids of rules whose scope selected nothing out of files, in the order the rules were given.

This is the one place the question is answered. `lint`'s empty-scope check and `check`'s scan summary both call it, because the two commands giving opposite verdicts about identical state is the defect #151 reports: lint FAILed the condition while check printed `[id] OK` at exit 0, one invocation apart, from two copies of this loop.

The predicate is config.Rule.Applies, not the prune census: scope.exclude and except.paths never reach the scan package, and an include glob that matches nothing leaves no trace anywhere — which is why the commonest real cause of a vacuous rule, a mistyped include, is invisible to any census-based diagnosis.

External-tool rules are excluded, matching lint's long-standing empty-scope exemption: their verdict comes from a shelled-out tool rather than from the files their scope selects, so an empty scope does not make them unable to fire and reporting them here would be noise.

It does NOT follow that they always run. A `command` rule carrying `when.paths_changed` skips silently when no scanned file matched that trigger — a separate gate (`whenSpec` / the `sawTrigger` check in command.FinalizeErr), not this scope predicate, and #53's shape. An earlier version of this comment asserted they "run regardless of what the tree holds", which is false in exactly that case. That skip is surfaced by SelfSkippedRules below, which asks the checker rather than the scope — still not here, because this predicate cannot see it.

func ScopeFloorFindings

func ScopeFloorFindings(rls []*config.Rule, files []*scan.File) []finding.Finding

ScopeFloorFindings returns one error-severity finding per rule whose scope selected fewer files than its declared scope.min_files floor, in the order the rules were given.

It is the ARMING end of the same question RulesMatchingNoFiles above reports. That one names a vacuous rule and changes no exit code, because an empty scope is legitimate — a rule scoped to a path the repo has not created yet is not a defect (#160). A finished port needs the other end: a way to say "this rule governs a corpus, and a run where that corpus vanished is a failure, not a pass". min_files is that, per rule, defaulting to 0 so every rule that does not declare one behaves exactly as it did before the key existed. The shipped precedent is set-relation's min_count, whose default 0 keeps empty∩empty green while a test-claim rule sets ≥1 so a zero-evidence join cannot pass.

Two deliberate divergences from RulesMatchingNoFiles, both because that predicate diagnoses every rule automatically while this one only ever fires on a number the operator typed:

  • External-tool rules are NOT exempt. The exemption there exists because a command rule's verdict comes from a shelled-out tool rather than from its scope, so calling it vacuous would be noise. An explicit floor on such a rule is not noise, it is a request, and ignoring it would leave a rule that reads as armed and cannot fail.
  • The finding is error severity whatever the rule's own severity is. A warn-severity shortfall exits 0, which is an armed floor that cannot fail the run — the exact shape the exit-code contract exists to prevent.

The finding is unexemptable, as spec §5 requires of every scope-level finding. The operative reason is that it never enters engine.Run: exemption is applied there, to findings the engine produced, and these are appended by the caller afterwards. Belt and braces, it also carries no Path, which is what engine.suppress returns early on, so even routed through the engine no marker could exempt it.

It counts the file set it is GIVEN and never re-walks, which is what lets the caller decide what its mode's floor is a claim about: whole-tree `check` hands it the walk, and a --staged/--range run hands it the tracked tree.

func SelfSkippedRules

func SelfSkippedRules(rls []*config.Rule) []report.SkippedRule

SelfSkippedRules returns, for every rule whose CHECKER declined to run itself, its id and the checker's reason — in the order the rules were given.

It answers the question RulesMatchingNoFiles above cannot: that one judges a rule by the SCOPE predicate, and a `command` rule's when.paths_changed gate is invisible to it. So a gate that shelled out to nothing passed both that check and the renderer's `[id] OK` (#159).

It must be called AFTER the engine has run: the SkipReporter contract requires a checker to answer false until it has actually declined, so over an un-run corpus this returns an empty list — a silent one, not a wrong one, which is why the caller's ordering is the thing tests have to pin.

func UnfollowedLinks(ignored []scan.Ignored) []string

UnfollowedLinks names every symlink the walk declined to follow, sorted by path, for report.ScanSummary.UnfollowedLinks.

ONE PLACE DECIDES WHICH RECORDS THESE ARE, and that is the point of the function rather than an inline loop at each consumer. `check`'s scan summary and `lint`'s escape-hatch enumeration are two commands describing the same state, and every time this repo has let them each compute it, they came to describe it differently (#151). The two callers are internal/cli's summary construction and enumerateEscapeHatches.

The sort makes the output deterministic on its own terms rather than by inheriting WalkWith's ordering, so a consumer diffing two runs is comparing the census and not the walk.

Types

type GitIgnoreResult

type GitIgnoreResult struct {
	State GitIgnoreState
	Set   *scan.GitIgnored // nil unless State is GitIgnoreOn
	Err   error            // why, when State is GitIgnoreUnknown
}

GitIgnoreResult is the resolved prune set plus how it was arrived at.

func ResolveGitIgnore

func ResolveGitIgnore(cfg *config.Config, root string) GitIgnoreResult

ResolveGitIgnore asks git which paths under root it ignores, when the config declares scan.gitignore.

WHY A GIT FAILURE IS NOT AN ERROR HERE, WHEN IT IS EVERYWHERE ELSE IN THIS ENGINE. The vcs package's contract is that callers must never soften a git failure, because every other consumer uses git to NARROW what is scanned — --staged, --range, the #90 tracked-set assertion — and a silent fallback there would gate a commit against the wrong, smaller file set. This consumer narrows too, but the fallback runs the other way: pruning nothing yields a scan that is a strict SUPERSET of the declared one, so no rule can pass that would otherwise have failed. Turning that into exit 2 would invent a new hard failure for the ordinary case of running over an exported tarball or a non-repo corpus — a false blocker, which is the very complaint this feature exists to answer (raised by the validating port).

The error is not swallowed: it is carried on the result so the census can name it, and callers surface it. Unanswered is reported as unanswered.

This lives in one place, reached by both `check` and `lint`, so the fail-closed decision cannot drift into two spellings.

func ResolveGitIgnoreFor added in v0.21.1

func ResolveGitIgnoreFor(cfg *config.Config, root string, paths []string) GitIgnoreResult

ResolveGitIgnoreFor is ResolveGitIgnore for a caller that will only ever look up the given paths and the directories above them — the path-scoped commands, check-content and rules-for, whose every lookup is scan.NotScannedBy or the ghost overlay over one queried path. The set holds exactly the records ResolveGitIgnore's would hold under those keys (vcs.IgnoredAmong), and git is asked about those keys only, instead of listing every ignored path in the working tree (#126). Everything else — the off and unanswerable states, and that an unanswerable git is carried on the result rather than returned — is ResolveGitIgnore's, for the same reasons.

A whole-tree walk must keep ResolveGitIgnore: it looks up every path it meets, and a set built for other keys would prune none of them.

func (GitIgnoreResult) Opts

func (r GitIgnoreResult) Opts(ignore []string) scan.Opts

Opts turns the result into the walk options for this run.

type GitIgnoreState

type GitIgnoreState int

GitIgnoreState is what the engine managed to learn about scan.gitignore for one run. The three states must stay distinct all the way to the report: "off" and "nothing was ignored" and "the question could not be answered" look identical in a bare count, and collapsing them is exactly the false clean this repo treats as its signature defect.

const (
	// GitIgnoreOff — the key is not declared. Nothing is pruned and nothing is
	// reported; an undeclared repo keeps its "escape hatches: none" contract.
	GitIgnoreOff GitIgnoreState = iota
	// GitIgnoreOn — git answered, and Set holds what it confirmed ignored.
	GitIgnoreOn
	// GitIgnoreUnknown — the key is declared but git could not answer (no
	// repository, no git binary, a broken index). Set is nil.
	GitIgnoreUnknown
)

Jump to

Keyboard shortcuts

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