ignore

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.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 ignore holds the parts of the ignore grammar (docs/schema/ignore.v1.md) that both the config resolver and the suppress stage need: rule validation and the forward-slash glob matcher. It imports only the standard library and model.

Index

Constants

View Source
const (
	MsgEmpty       = "value is empty"
	MsgBadID       = "id must be th_ followed by 16 lowercase hex characters"
	MsgBadDetector = "detector id must not contain whitespace"
	MsgBadLine     = "line must be a positive decimal integer"
	MsgAbsolute    = "path must be relative"
	MsgParent      = "path must not contain a .. segment"
	MsgBadGlob     = "invalid glob"
	MsgBadKind     = "unknown rule kind"
	MsgBadScope    = "unknown rule scope"
	MsgBadMachine  = "machine path must start with ~/"
	MsgBackslash   = "path must use forward slashes"
	MsgBadSegment  = "path must not contain empty or . segments"
)

Validation messages. They never contain the rule value.

Variables

View Source
var (
	ErrEmpty       = errors.New(MsgEmpty)
	ErrBadID       = errors.New(MsgBadID)
	ErrBadDetector = errors.New(MsgBadDetector)
	ErrBadLine     = errors.New(MsgBadLine)
	ErrAbsolute    = errors.New(MsgAbsolute)
	ErrParent      = errors.New(MsgParent)
	ErrBadGlob     = errors.New(MsgBadGlob)
	ErrBadKind     = errors.New(MsgBadKind)
	ErrBadScope    = errors.New(MsgBadScope)
	ErrBadMachine  = errors.New(MsgBadMachine)
	ErrBackslash   = errors.New(MsgBackslash)
	ErrBadSegment  = errors.New(MsgBadSegment)
)

Validation errors.

Functions

func Check

func Check(r model.IgnoreRule) error

Check validates a rule built by a parser or a library caller.

func CheckPath

func CheckPath(p string, glob bool) error

CheckPath checks the forward-slash path or glob p of a path or loc rule: not empty, relative (no leading "/" and no drive letter), no ".." segment, and (for a glob) every segment a valid path.Match pattern. A backslash is rejected: on every OS patterns use forward slashes, and a backslash would be read as a glob escape.

func Message

func Message(err error) string

Message returns the fixed message of a validation error without reading error text (AD-3), or "invalid rule" for any other error.

func ValidID

func ValidID(id string) bool

ValidID reports whether id is a finding id.

Types

type Glob

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

Glob is a compiled forward-slash glob: "**" is zero or more segments, other segments are path.Match patterns. Matching is case-sensitive on every OS.

func Compile

func Compile(p string) (Glob, error)

Compile compiles a glob checked by CheckPath. A trailing "/" means "/**".

func (Glob) Match

func (g Glob) Match(name string) bool

Match reports whether the forward-slash path name matches the glob. It runs in O(len(pattern) * len(name)) time: every (pattern, name) position is tried once, so many "**" segments from an untrusted ignore file cannot backtrack exponentially.

Jump to

Keyboard shortcuts

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