ignore

package
v3.67.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ignore implements .gitignore-style path matching shared by the scan and sast filesystem walkers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

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

Matcher evaluates paths against a stack of .gitignore files discovered during a top-down filesystem walk. It implements the subset of gitignore(5) semantics that matters for scan pruning: comments, negation (`!`), anchored patterns (leading or embedded `/`), directory-only patterns (trailing `/`), and `*` / `?` / `**` / `[...]` globs.

Rules are accumulated per directory: call LoadDir on each directory as the walk enters it (parents before children, which filepath.WalkDir guarantees), then Ignored to test each entry. Because ignored directories are pruned with SkipDir, a negation cannot re-include a file whose parent directory is ignored — this matches git's own behaviour.

func New

func New() *Matcher

New returns an empty matcher.

func (*Matcher) Ignored

func (m *Matcher) Ignored(relPath string, isDir bool) bool

Ignored reports whether the slash-relative path (relPath) should be excluded. Later matching rules win, so negations placed after a broad ignore re-include.

func (*Matcher) LoadDir

func (m *Matcher) LoadDir(absDir, relDir string)

LoadDir reads a .gitignore in absDir (whose slash-relative path from the walk root is relDir, "" for the root) and appends its rules. Missing or unreadable files are silently ignored.

Jump to

Keyboard shortcuts

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