suppress

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 7 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 is the fourth pipeline stage: it alone decides whether a candidate is suppressed (test keys, inline allows, allowlists, ignore files, baselines) and records the reason.

Index

Constants

View Source
const Default = "default"

Default is the name of the default suppressor.

Variables

View Source
var ErrInvalidBaseline = errors.New("suppress: invalid baseline")

ErrInvalidBaseline is returned by the default factory for a baseline with a schema version above model.BaselineSchemaVersion or a malformed finding id. The error names the finding index, never its value.

View Source
var ErrInvalidRule = errors.New("suppress: invalid ignore rule")

ErrInvalidRule is returned by the default factory for a rule that fails validation. The error names the rule index, never its value.

Functions

func Register

func Register(name string, f Factory)

Register adds a suppress adapter. Adapters call it from init().

Types

type Factory

type Factory func(Options) (Suppressor, error)

Factory builds a Suppressor.

func Lookup

func Lookup(name string) (Factory, bool)

Lookup returns the suppress adapter registered under name.

type Options

type Options struct {
	// IncludeTestKeys keeps findings from generated test keys unsuppressed.
	IncludeTestKeys bool
	// Rules are the ignore rules to apply.
	Rules []model.IgnoreRule
	// Baseline is the accepted set of findings Compare uses; nil means none.
	Baseline *model.Baseline
	// NoInlineAllow ignores inline tokenhound:allow markers: they cover no location.
	NoInlineAllow bool
}

Options configures a suppressor.

type Suppressor

type Suppressor interface {
	// Suppress decides on c as it stands: its Locations and c.Ctx (Allows and
	// FirstID). It only ever sets Suppressed and SuppressionReason.
	Suppress(c *candidate.Candidate)
	// Hold reports whether c must wait for every location before its decision: its
	// first location is covered by a location-level fact and no id or detector rule
	// decides it already. Locations seen later may be uncovered, so a held
	// candidate is decided again on the merged locations.
	Hold(c candidate.Candidate) bool
	// Compare sets NewVsBaseline on an unsuppressed finding when a baseline is
	// loaded: false when f's id (its final id) is in the baseline, true otherwise.
	// Suppressed findings and runs without a baseline keep it nil. It changes no
	// other field and never changes a suppression decision.
	Compare(f *model.Finding)
}

Suppressor is the suppress stage interface. Only suppress sets the Finding's Suppressed and SuppressionReason fields, and it never reads key material: it decides from the Finding's id, detector and locations and from the predicates detect precomputed (SuppressCtx).

Finding-level facts (an id or detector rule, the test marker) suppress the whole finding. Location-level facts (path and loc rules, inline allow markers) suppress it only when every location is covered by at least one of them. The reason is the first one in model.SuppressionReasons order among everything that matched.

func New added in v0.2.0

func New(o Options) (Suppressor, error)

New compiles the rules once and returns the default suppressor.

Jump to

Keyboard shortcuts

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