filter

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package filter provides file filtering helpers.

Package filter provides file filtering helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasInlineIgnore

func HasInlineIgnore(line string) bool

HasInlineIgnore reports whether line contains the generic inline ignore marker "leakwatch:ignore". The marker may appear anywhere in the line (typically inside a comment).

func HasInlineIgnoreForDetector

func HasInlineIgnoreForDetector(line string, detectorID string) bool

HasInlineIgnoreForDetector reports whether line contains the detector- specific inline ignore marker "leakwatch:ignore:<detectorID>". It also returns true when the generic "leakwatch:ignore" marker (without a detector suffix) is present.

func IsBinaryFile

func IsBinaryFile(data []byte) bool

IsBinaryFile checks whether data appears to be a binary file. If a null byte is found within the first 8KB, it is considered binary. UTF-16 text (identified by a leading BOM) is exempted from the null-byte heuristic: UTF-16 encodes every ASCII character with an accompanying 0x00 byte, so it would otherwise always be misclassified as binary.

func IsExcludedExtension

func IsExcludedExtension(path string, extraExts []string) bool

IsExcludedExtension checks whether a file extension should be excluded.

func IsSkippedFilename

func IsSkippedFilename(path string) bool

IsSkippedFilename checks whether a filename should be skipped.

func LineHasInlineIgnore

func LineHasInlineIgnore(data []byte, lineNum int, detectorID string) bool

LineHasInlineIgnore reports whether the 1-based lineNum in data carries an inline ignore marker (generic or detector-specific) for detectorID. It returns false when lineNum is out of range or non-positive, which lets callers use it as a single guard regardless of whether line tracking is available for a given source.

func MatchesGlob

func MatchesGlob(path string, patterns []string) bool

MatchesGlob reports whether path matches any of the given glob patterns. It supports three pattern styles:

  • standard filepath.Match globs (e.g. "*.yaml"), tried against both the full path and the base filename so simple patterns match nested files;
  • "**" (double-star) patterns matched segment-by-segment so "**" spans zero or more directory segments;
  • gitignore-style directory patterns with a trailing slash (e.g. "build/"), which match every path inside a directory of that name at any depth.

A pattern with invalid glob syntax never matches: filepath.Match's error is logged at debug level and treated as a non-match, so one malformed exclude pattern cannot abort filtering. (Previously the doc claimed an error was returned, which the bool signature could not honor — CFG-m-03.)

Types

type IgnoreRules

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

IgnoreRules holds the parsed patterns from a .leakwatchignore file.

func LoadIgnoreFile

func LoadIgnoreFile(path string) (*IgnoreRules, error)

LoadIgnoreFile reads and parses a .leakwatchignore file at the given path. Lines starting with '#' are treated as comments and blank lines are skipped. A '!' prefix negates the pattern (un-ignores a previously ignored path).

func (*IgnoreRules) ShouldIgnore

func (r *IgnoreRules) ShouldIgnore(path string) bool

ShouldIgnore reports whether path matches the ignore rules. Patterns are evaluated in order; the last matching pattern wins. A negated pattern (!) re-includes a previously ignored path.

Jump to

Keyboard shortcuts

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