Documentation
¶
Overview ¶
Package filter provides file filtering helpers.
Package filter provides file filtering helpers.
Index ¶
- func HasInlineIgnore(line string) bool
- func HasInlineIgnoreForDetector(line string, detectorID string) bool
- func IsBinaryFile(data []byte) bool
- func IsExcludedExtension(path string, extraExts []string) bool
- func IsSkippedFilename(path string) bool
- func LineHasInlineIgnore(data []byte, lineNum int, detectorID string) bool
- func MatchesGlob(path string, patterns []string) bool
- type IgnoreRules
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasInlineIgnore ¶
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 ¶
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 ¶
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 ¶
IsExcludedExtension checks whether a file extension should be excluded.
func IsSkippedFilename ¶
IsSkippedFilename checks whether a filename should be skipped.
func LineHasInlineIgnore ¶
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 ¶
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.