ignore

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 5 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 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 Globs

func Globs(patterns []string) *Matcher

Globs returns a matcher for user-supplied exclusion patterns (--exclude, --ignore), each relative to the walk root. They follow the rules of a root .gitignore, which is what people expect when they type one: a trailing `/` names a directory and everything beneath it, a pattern with no slash matches that name at any depth, and `**` spans directories. A leading `./` anchors the pattern to the root, as a leading `/` does.

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