Documentation
¶
Overview ¶
Package ignore implements gitignore-compatible file filtering.
It supports the full gitignore rule set: negation (!), directory-only (/), anchored (/prefix), recursive globs (**), and negation re-inclusion. Rules cascade via a parent chain — child rules take precedence.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var FileTypes = map[string][]string{
"go": {"*.go"},
"rust": {"*.rs"},
"python": {"*.py", "*.pyi"},
"js": {"*.js", "*.jsx", "*.mjs", "*.cjs"},
"ts": {"*.ts", "*.tsx", "*.mts", "*.cts"},
"c": {"*.c", "*.h"},
"cpp": {"*.cpp", "*.hpp", "*.cc", "*.hh", "*.cxx", "*.hxx"},
"zig": {"*.zig", "*.zon"},
"java": {"*.java"},
"kotlin": {"*.kt", "*.kts"},
"scala": {"*.scala", "*.sc"},
"swift": {"*.swift"},
"csharp": {"*.cs"},
"ruby": {"*.rb", "*.rake", "Rakefile", "Gemfile"},
"php": {"*.php", "*.phtml"},
"lua": {"*.lua"},
"html": {"*.html", "*.htm"},
"css": {"*.css", "*.scss", "*.sass", "*.less"},
"md": {"*.md", "*.markdown"},
"json": {"*.json", "*.jsonc", "*.json5"},
"yaml": {"*.yaml", "*.yml"},
"toml": {"*.toml"},
"sql": {"*.sql"},
"sh": {"*.sh", "*.bash", "*.zsh"},
"fish": {"*.fish"},
"make": {"Makefile", "*.mk", "GNUmakefile"},
"docker": {"Dockerfile", "*.dockerfile"},
"proto": {"*.proto"},
"graphql": {"*.graphql", "*.gql"},
}
FileTypes maps type names to glob patterns.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// GlobIncludes is the list of glob patterns to always include.
GlobIncludes []string
// GlobExcludes is the list of glob patterns to always exclude.
GlobExcludes []string
// Types is the list of file types to include (e.g., "go").
Types []string
// TypesNot is the list of file types to exclude.
TypesNot []string
// NoIgnore disables .gitignore/.ignore file loading.
NoIgnore bool
// Hidden includes hidden files and directories.
Hidden bool
}
Config holds ignore engine options.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine manages ignore rules and glob filters for file traversal.
func NewEngineFS ¶
NewEngineFS creates an ignore engine from the given config and filesystem.
func (*Engine) GetIgnoreRules ¶
func (e *Engine) GetIgnoreRules(dir string) []IgnoreRule
GetIgnoreRules returns the loaded ignore rules for a directory.
func (*Engine) LoadIgnoreFile ¶
func (e *Engine) LoadIgnoreFile(dir string) (IgnoreContext, error)
LoadIgnoreFile reads .gitignore and .ignore files from the given directory. It returns an IgnoreContext that can be used for subsequent ShouldIgnore calls in this directory.
func (*Engine) ShouldIgnore ¶
func (e *Engine) ShouldIgnore(path string, isDir bool, ctx ...IgnoreContext) bool
ShouldIgnore returns true if the path should be excluded from traversal. path MUST be cleaned and use forward slashes (normalized by Walker). If ctx is provided, it avoids redundant trie traversals.
type IgnoreContext ¶
type IgnoreContext struct {
// contains filtered or unexported fields
}
IgnoreContext holds the state for ignore lookups in a specific directory. It can be passed to ShouldIgnore to avoid redundant trie traversals.
type IgnoreRule ¶
type IgnoreRule struct {
// Pattern is the glob pattern to match.
Pattern string
// Negated is true if the pattern starts with !.
Negated bool
// DirectoryOnly is true if the pattern ends with /.
DirectoryOnly bool
// Anchored is true if the pattern starts with /.
Anchored bool
// Source is the path to the file that defined this rule.
Source string
}
IgnoreRule is a single parsed gitignore rule.
type IgnoreSet ¶
type IgnoreSet struct {
// Dir is the directory this ignore file lives in.
Dir string
// DirBase is the base name of the directory (cached for performance).
DirBase string
// Rules is the list of parsed rules from the ignore file.
Rules []IgnoreRule
// Parent is the parent directory's ignore set.
Parent *IgnoreSet
}
IgnoreSet holds all ignore rules for one ignore file (.gitignore/.ignore). Rules are ordered top-to-bottom; the last match wins.