Documentation
¶
Overview ¶
Package report renders findings. The human format preserves the verdict contract downstream tooling and habits depend on: [rule-id] OK/FAIL lines and Cure blocks (spec §6).
scan.go — the scan summary (#151 rows 1-8, 13). Split from format.go, which the 750-line vendor cap bounds; same package.
Index ¶
- Constants
- func GitHub(w io.Writer, rls []*config.Rule, findings []finding.Finding, scan ScanSummary)
- func Human(w io.Writer, rls []*config.Rule, findings []finding.Finding, scan ScanSummary)
- func JSON(w io.Writer, rls []*config.Rule, findings []finding.Finding, scan ScanSummary, ...)
- func Render(format string, w io.Writer, rls []*config.Rule, findings []finding.Finding, ...) error
- func UnfollowedLinkLine(path string) string
- func ValidFormat(format string) error
- type PruneChannel
- type ScanSummary
- type SkippedRule
Constants ¶
const ( SkipChannelSelf = "self-skip" SkipChannelSkipEscapes = "skip-escapes" // SkipChannelCostMax is the operator narrowing the run by cost class // (check --cost-max, #22): the same kind of drop as --skip-escapes, // carried on its own channel so a consumer can tell the two apart. SkipChannelCostMax = "cost-max" )
Skip channels. Two things stop a rule running, and they are different in kind: a checker declining its own gate is the rule behaving as configured, while --skip-escapes is an operator narrowing this run. A CI that wants to alert on the second and not the first must be able to tell them apart without string-matching prose, which is why PruneChannel below carries a Channel too.
SkipChannelSelf is gate-agnostic on purpose. The code that sets it, meta.SelfSkippedRules, asks the generic rules.SkipReporter interface, and that interface does not say WHICH gate a checker took — so a trigger-specific value like "when-trigger" would be a claim the producing code cannot support, true only for as long as `command`'s when.paths_changed happens to be the sole implementor. What this channel can back is the distinction that matters to a consumer: the rule declined itself, versus an operator narrowed the run. The gate specifics live in the reason text, where the checker that knows them writes them.
Variables ¶
This section is empty.
Functions ¶
func GitHub ¶
GitHub emits one workflow-command annotation per live finding (`::error file=…,line=…::message`), so violations show inline on a PR — then one `::notice` per suppressed finding (#91), naming what was exempted and through which channel, after the live annotations because reviewers read failures first. Notice level can never read as a failure and never affects the exit code (renderers are post-verdict). A live annotation whose rule declares cure: carries it appended to the message (#107) — workflow commands have no extra structured field, so the cure travels as message data, escaped like the rest of it; suppressed notices don't carry cure, because an exempted finding is not asking to be remediated.
rls must be the complete loaded rule set the findings were produced from (it was ignored before #107): each annotation's cure joins from it by rule id, so a nil or filtered rls silently drops declared cures.
func Human ¶
Human writes the per-rule verdicts and summary. rls must be in the order to display (config.Load returns them ID-sorted); findings may be in any order but are conventionally pre-sorted by the engine, and may include Suppressed entries (spec §5 exemptions) — Human owns filtering those out of the per-rule verdicts and finding tally itself (report owns all formatting).
SUPPRESSED FINDINGS ARE ENUMERATED, NOT COUNTED (#57). Each one gets a line naming its rule, location, message and the channel that exempted it ("marker") — the same facts JSON and GitHub carry (#91) — under a heading that says in words that these are exemptions rather than failures. A bare integer told a reader that something was exempted and never what, so the surface could not be audited or burned down from `check` output at all; downstream, `1335/1335 rules passed, 0 findings, 14 suppressed` was quoted as a clean bill by several readers who had no affordance to ask which fourteen.
The summary's count is len(that enumeration), deliberately: computing it independently as len(findings)-len(live) is what let a count exist with no list beside it to disagree with. One source, so they cannot drift.
The scan block sits between the per-rule verdicts and the summary line: the verdicts are what the run found, the block is what it looked at to find it, and the summary line stays last because habits and downstream tooling read it there. The suppressed block sits directly above that summary line — as close as possible to the number it produces.
func JSON ¶
func JSON(w io.Writer, rls []*config.Rule, findings []finding.Finding, scan ScanSummary, timing map[string]time.Duration)
JSON emits a stable machine-readable report: the live (unsuppressed) findings, the suppressed findings enumerated, and a summary whose suppressed count is the length of that enumeration — derived, not asserted alongside, so the two cannot drift (#91). Findings arrive engine-sorted, so output is deterministic.
rls must be the complete loaded rule set the findings were produced from: each live finding's cure joins from it by rule id (#107), so a nil or filtered rls silently drops declared cures (and skews rules_total/passed).
timing (may be nil) renders as the report's durations map; Go marshals map keys sorted, so the output stays deterministic run to run.
func Render ¶
func Render(format string, w io.Writer, rls []*config.Rule, findings []finding.Finding, scan ScanSummary, timing map[string]time.Duration) error
Render writes findings in the named format (spec §6): "human" (default), "json", or "github". An unknown format is an error (the caller exits 2).
scan travels to every renderer, by value, so that no format can be the one that drops it (#151). -format github used to write zero bytes for a run with no findings, which made it the surface where a scan that looked at nothing was most invisible and the surface adopters most often read.
func UnfollowedLinkLine ¶
UnfollowedLinkLine renders one unfollowed-symlink disclosure. It is the single formatter for these lines, so `check`'s scan summary and `lint`'s escape-hatch enumeration cannot describe the same skip in different words — the same reason PruneChannel and SkippedRule own their own Line.
The reason is carried by the formatter rather than by the value, because it is invariant: every entry here is skipped for the one reason that formwork never follows a link. A per-entry reason field would be a slot for a divergence that cannot exist.
func ValidFormat ¶
ValidFormat reports whether format names a renderer, without rendering anything. It exists so a caller can reject a mistyped -format up front, beside its other flag validation, instead of discovering it here after a whole scan has run — by which point the operator has waited for work whose output cannot be printed, and (once the caller grew other config-level refusals) may be told about their config instead of their typo.
ADDING A RENDERER MEANS EDITING BOTH THIS LIST AND Render's SWITCH. The first cut of this comment said "adding a renderer means adding one case below and nothing else", which was an instruction into a silent fail: a format accepted here but unhandled there rendered zero bytes and returned nil, so a run with violations printed nothing. Render keeps a default: arm precisely so that mistake is loud instead.
Types ¶
type PruneChannel ¶
type PruneChannel struct {
Channel string // "scan.ignore" or "scan.gitignore"
Glob string // the declared glob; empty for scan.gitignore, which has none
Reason string // the operator's declared reason
Dirs int
Files int
// Undetermined carries git's failure when scan.gitignore was declared but
// could not be resolved. It is reported in words, never as a count:
// "0 matches" asserts that git was asked and said none, and a run where git
// could not answer must not be able to borrow that sentence.
Undetermined string
}
PruneChannel is one declared prune channel and what it removed. Dirs counts pruned directories rather than the files under them: the walk did not descend, so a file count would have to be invented at the cost of what the prune saved (#56).
func (PruneChannel) Line ¶
func (p PruneChannel) Line() string
Line renders one channel. It is the single formatter for these lines: both `check`'s scan summary and `lint`'s escape-hatch enumeration call it, so the two commands cannot describe the same channel differently — which is the failure mode #151 is about one level up.
type ScanSummary ¶
type ScanSummary struct {
// FilesScanned is how many files the rules were evaluated over. Under
// --staged/--range that is the restricted set, which is what those flags
// asked about.
FilesScanned int
// PathsRequested is how many paths git NAMED under --staged/--range, and is
// 0 in a whole-tree run (FileSetMode is the discriminator, not this).
//
// It exists because the difference between the two counts is the only thing
// that separates "you asked for nothing" from "you asked for paths and I
// could not see any of them" — and those rendered identically before.
//
// WHAT STILL REACHES THE GAP is now narrow, and the list that used to be here
// named three defects by number, which was the wrong frame twice over — an
// issue's state is not a fact about this struct, and two of the three had
// moved on. Stated as shapes instead:
//
// - A path git named that the scan did not produce is now REFUSED at exit
// 2 by #158's fix, before any summary renders. Whatever the cause — a
// spelling mismatch between git's name and the on-disk one included — it
// no longer arrives here to be counted.
// - A pathspec that yields no paths at all produces no gap: both counts
// are 0, and there is nothing to differ.
//
// What is left is the deliberate carve-outs — a symlink or a submodule
// gitlink git named, which the walk produces for nobody and which the run is
// right not to refuse. That is why
// TestCheckStagedDistinguishesRequestedFromScanned had to be rebuilt around
// a symlink: it is the only construction that still reaches this state.
PathsRequested int
// FileSetMode names the flag that restricted the run ("--staged", "--range
// <spec>"), empty for a whole-tree run.
FileSetMode string
// InvariantRules counts rules that BYPASSED the changeset entirely: a
// whole-repo invariant is non-monotonic under file removal, so it evaluates
// over the tracked tree even in a file-set run (#4). Reporting the
// changeset's size beside "N/N rules passed" without saying so is a
// manufactured coverage claim — those rules did not read those files.
InvariantRules int
// RulesMatchingNoFiles names the rules whose scope selected nothing out of
// what was scanned, in the order the rules were given. External-tool rules
// are absent (see meta.RulesMatchingNoFiles for why).
//
// It is populated only for a WHOLE-TREE run. Vacuity is a whole-tree
// question: under --staged a rule that does not cover this commit is not
// vacuous, it is merely irrelevant to it, and naming every such rule would
// bury the real signal on the path that runs most — the pre-commit shim.
RulesMatchingNoFiles []string
// RulesNotRun names the rules that reached no verdict at all, with the reason,
// in the order they were given. Two channels feed it and the reason says
// which: a CHECKER that declined to run itself (`command`'s
// when.paths_changed, whose tool never ran), and a rule the CLI filtered out
// before the engine (--skip-escapes). Both rendered `[id] OK` or nothing at
// all — indistinguishable from a rule whose tool ran and passed (#159).
//
// One list rather than one per channel, because the operator's question is
// "which rules did not run, and why", and answering it from two places is how
// two commands came to describe the same state differently (#151).
//
// Unlike RulesMatchingNoFiles this is populated in EVERY mode, whole-tree and
// file-set alike, and the difference is deliberate. Vacuity is a whole-tree
// question — under --staged a rule that does not cover the commit is
// irrelevant, not vacuous. A rule that did not run is not: a file-set run is
// where a paths_changed trigger goes unmatched, so suppressing it there would
// suppress it where it fires.
RulesNotRun []SkippedRule
// Prunes enumerates the DECLARED prune channels with live counts. Only
// scan.ignore and scan.gitignore appear, because a channel here is built
// per config entry and those are the only two an operator declares.
// Built-in skips, scope.exclude and except.paths are NOT here: the first is
// never recorded by the walk, and the last two are rule fields the scan
// package never sees — which is why RulesMatchingNoFiles is computed from
// the scope predicate rather than derived from this census.
//
// Nor are unfollowed symlinks, and that one is not an omission — see
// UnfollowedLinks below, which is their peer field. (Before #235 they
// really were unrecorded, and this comment said so; the walk has recorded
// them since, so the sentence that grouped them with the built-in skips has
// been corrected rather than carried forward.)
Prunes []PruneChannel
// UnfollowedLinks names every symlink the WALK declined to follow, sorted
// by path. It is a PEER of Prunes and deliberately not a member of it: a
// PruneChannel is one thing the operator DECLARED and what it removed, and
// an unfollowed link is declared nowhere — no glob, no .gitignore line — so
// there is nothing for a channel to key on. meta.PruneChannels says the
// same from the producing side.
//
// That absence of a declaration is exactly why the list is owed. The walk
// skips such a link rather than refusing it (#143 chose the third option
// for a name no toolchain compiles), and until #309 the record reached only
// `formwork lint` — so `check` reported `0 finding(s)` at exit 0 over a
// path it never opened, with every vacuity indicator empty. Reporting what
// a run did NOT look at is half of what this type is for.
//
// It changes no verdict. The walk follows no symlink in any mode, and this
// is the disclosure of that fact, not a new gate in front of it.
UnfollowedLinks []string
}
ScanSummary is what a run reports about the SCAN, as opposed to about the findings: how much it looked at, which rules had nothing to look at, and what each declared prune channel removed from the walk.
It exists because "0 finding(s)" answers only half the question an operator is asking. A rule that matched no files and a rule that matched files and found nothing both render `[id] OK`, and a scan that saw zero files renders the same summary line as a clean tree — so `check` could not distinguish a green repo from one it never looked at (#151).
Every renderer emits it. The value type makes the ARGUMENT non-omittable at the call site; what makes the OUTPUT non-omittable is a test per format — TestHumanZeroRules, TestGitHubEmitsScanSummaryWithNoFindings and TestCheckScanSummaryReachesJSON. An optional disclosure is one an adopter's CI does not have.
type SkippedRule ¶
SkippedRule is one rule that did not run, and why. Reason is the explanation its channel supplies, rendered verbatim: report owns the layout, the channel owns the words, since only it knows what stopped the rule. Channel is that same fact structurally, for machine consumers.
func (SkippedRule) Line ¶
func (s SkippedRule) Line() string
Line renders one entry. It is the single formatter for these lines, so the human and github renderers cannot describe the same skip differently — the same reason PruneChannel below owns its own Line.
An empty reason still produces a line: a rule that did not run without explaining itself must be visible as such rather than absent, which is the whole failure this type exists to remove.