ignore

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ignore loads .codesearchignore (gitignore syntax) and walks the repo skipping ignored paths, oversized files, and binary content.

Index

Constants

View Source
const (
	// DefaultMaxFileSize is the size cap applied when Walk is called with
	// maxFileSize == 0.
	DefaultMaxFileSize int64 = 1 * 1024 * 1024 // 1 MiB

)
View Source
const IgnoreFileName = ".codesearchignore"

IgnoreFileName is the per-repo ignore file read by Load.

Variables

This section is empty.

Functions

func Walk

func Walk(root string, matcher *Matcher, maxFileSize int64, fn WalkFn) error

Walk iterates the filesystem under root, skipping:

  • directories matched by the Matcher,
  • files matched by the Matcher,
  • empty files,
  • files larger than maxFileSize (or DefaultMaxFileSize when 0),
  • files whose first 512 bytes contain a null byte (binary heuristic).

Paths passed to fn are repo-relative with forward slashes regardless of the host OS.

Types

type Entry

type Entry struct {
	Path string // repo-relative, forward slashes
	Info fs.FileInfo
}

Entry is a file accepted by Walk: not ignored, not empty, not oversized, and not likely-binary.

type Matcher

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

Matcher reports whether a repo-relative path is ignored.

func Load

func Load(root string) (*Matcher, error)

Load reads root/.codesearchignore (if present) and combines it with the built-in defaults. A missing ignore file is not an error.

func (*Matcher) Match

func (m *Matcher) Match(relPath string) bool

Match returns true when relPath (forward-slash, repo-relative) is ignored.

type WalkFn

type WalkFn func(Entry) error

WalkFn is invoked once per accepted entry. Returning an error stops the walk; returning filepath.SkipDir from inside fn is not supported (use the Matcher to exclude directories).

Jump to

Keyboard shortcuts

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