suppress

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: GPL-3.0 Imports: 6 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 suppress implements signal control SC2 (ADR-0027): inline, in-source suppression of a single finding via a visible, reasoned comment marker on (or directly above) the offending line.

The marker is `commitbrief-ignore: <reason>`, `commitbrief-ignore[<severity>]: <reason>` or `commitbrief-ignore[<rule_id>]: <reason>`. A severity-scoped marker silences only that severity on the line, a rule-scoped marker only findings of that rule (`sec.injection`) or rule category (`sec.*`); an unscoped marker silences any. A bracket token containing a dot is a rule scope, a dotless one is a severity scope (severity names never contain a dot, rule ids always do), so the two never collide. The reason is everything after the colon and is required only insofar as the marker must parse — an empty reason still suppresses, but the syntax is documented as "give a reason".

A marker is bound to the file it appears in: it is keyed by (path, line), so a marker in one file never silences a finding on the same line number of another file.

Unlike the user-private baseline, a suppression marker lives in committed source: a reviewer sees it in the diff, so it cannot be used to silently hide a real bug from a senior. That is why suppression carries none of the baseline's team-shared hide-vector risk.

Markers are read from the ADDED lines of the diff (the new content of the change under review). The comment prefix is not parsed — the `commitbrief-ignore` token is matched language-independently, so `//`, `#`, `--`, and `/* ... */` comments all work without a per-language table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter(findings []render.Finding, sup Suppressions) (kept []render.Finding, suppressed int)

Filter splits findings into the ones to KEEP and a count of how many were dropped by an inline suppression. A finding is dropped when a matching marker sits on its own line OR on the line directly above it (line-1) of the SAME file — the "above" case is the idiomatic placement when the offending statement is long or the marker would clutter the line. This is a TRUE removal (ADR-0027): the kept slice feeds fail-on, JSON findings[], and display alike. An empty suppression set keeps everything. The kept slice is always non-nil so the nil-means-degrade invariant downstream is preserved.

Types

type Key added in v1.19.0

type Key struct {
	Path string
	Line int
}

Key addresses a marker: the canonical path of the file it sits in and its new-file line number. Keying by line alone (the pre-1.19 behaviour) let a marker in one file silence a finding on the same line of another.

type Rule

type Rule struct {
	Severity render.Severity
	RuleID   string
	Reason   string
}

Rule is one parsed suppression directive bound to a new-file line number. At most one of Severity and RuleID is set: Severity is one of the five canonical levels for a severity-scoped marker, RuleID is a canonical taxonomy id (`sec.injection`) or a category wildcard (`sec.*`) for a rule-scoped one, and both are empty for an unscoped marker (suppresses any finding on the line). Reason is the free text after the colon, trimmed; it is retained so a future surface (or audit log) can echo why a finding was silenced.

type Suppressions

type Suppressions struct {
	// contains filtered or unexported fields
}

Suppressions holds the markers found in a diff, keyed by (path, line). Only one directive per line is retained (the first match wins; a line with two markers is pathological and not worth modeling). The zero value is an empty set and is safe to use.

func ParseSuppressions

func ParseSuppressions(d diff.Diff) Suppressions

ParseSuppressions scans the ADDED lines of d for commitbrief-ignore markers and returns them keyed by (path, new-file line number) — the same 1-based numbering a finding's Line field uses (see diff.NumberedString). Context and removed lines are ignored: a suppression must be part of the change under review, not pre-existing untouched code. Returns an empty set when there are no markers.

func (Suppressions) At added in v1.19.0

func (s Suppressions) At(path string, line int) (Rule, bool)

At returns the marker at (path, line), if any. The path is canonicalised the same way finding fingerprints are, so "./a.go" and "a.go" address the same file.

func (Suppressions) Len added in v1.19.0

func (s Suppressions) Len() int

Len returns the number of markers. Safe on the zero value.

func (Suppressions) Warnings added in v1.19.0

func (s Suppressions) Warnings() []Warning

Warnings returns the markers with an unrecognised scope, ordered by path then line so the output is deterministic.

type Warning added in v1.19.0

type Warning struct {
	Path string
	Line int
	// Token is the bracket content as written (lowercased).
	Token string
	// UnknownRule is true when the token looked like a rule id (it contains a
	// dot) but is not in the taxonomy; false when it is neither a severity nor
	// a rule-shaped token.
	UnknownRule bool
}

Warning reports a marker whose bracket scope could not be understood. The marker still suppresses (fail-open, ADR-0027: it is visible in the diff), but as an unscoped one, so the typo is surfaced rather than silently widening or narrowing what is hidden.

Jump to

Keyboard shortcuts

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