ignore

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package ignore is the canonical .devstrapignore compiler (DRAFT-03). It is the single source of truth for what content is excluded from draft bundles, pruned by the scanner, skipped by the watcher, denied to agents, and emitted into generated .gitignore/.dockerignore fragments. One compiled policy feeds every consumer so the four previously-divergent hardcoded lists cannot drift.

Pattern semantics follow .gitignore (https://git-scm.com/docs/gitignore):

  • Blank lines and lines starting with "#" are ignored.
  • A leading "!" negates a pattern (last matching pattern wins).
  • A trailing "/" makes the pattern directory-only.
  • A leading "/" anchors the pattern to the root.
  • A leading "**/" matches in all directories.
  • A trailing "/**" matches everything inside.
  • "*" matches anything except "/"; "?" matches any single char except "/".
  • "**" between slashes matches zero or more directories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultGitignoreFragment

func DefaultGitignoreFragment() string

DefaultGitignoreFragment returns the default junk patterns as a .gitignore fragment.

Types

type Matcher

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

Matcher is an ordered list of compiled patterns evaluated last-match-wins, exactly like .gitignore. A Matcher is safe for concurrent Match calls once construction is complete.

func Compile

func Compile(source string, includeDefaults bool) (*Matcher, error)

Compile parses source text into a Matcher. When includeDefaults is true the canonical OS-junk and build-artifact patterns (DefaultJunk) are prepended so every consumer gets the same baseline exclusions.

func CompileFromDir

func CompileFromDir(dir string, includeDefaults bool) (*Matcher, error)

CompileFromDir reads a .devstrapignore file from dir (if present) and compiles it with the default junk patterns prepended.

func DefaultMatcher

func DefaultMatcher() *Matcher

DefaultMatcher returns a Matcher containing only the canonical OS-junk and build-artifact patterns.

func (*Matcher) GitignoreFragment

func (m *Matcher) GitignoreFragment() string

GitignoreFragment returns the compiled patterns as a .gitignore-compatible text block suitable for emitting into a project's .gitignore or .dockerignore (DRAFT-03 generated-ignore target).

func (*Matcher) Match

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

Match reports whether relPath (forward-slash relative to the project root) is ignored. isDir indicates whether the path is a directory so that directory-only (trailing-slash) patterns match correctly.

func (*Matcher) ShouldPruneDir

func (m *Matcher) ShouldPruneDir(name, relSlash string) bool

ShouldPruneDir is a fast path for the scanner walk: it reports whether a directory entry should be pruned (skipped entirely) based on the compiled policy. name is the directory base name; relSlash is the forward-slash path relative to the scan root. Callers must pass the true root-relative path for non-root directories — relSlash is authoritative so anchored patterns (e.g. "/dist/") and negations (e.g. "!keep/build/") are evaluated against the full path rather than silently falling back to the bare name.

type Pattern

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

Pattern is a single compiled .devstrapignore pattern.

Jump to

Keyboard shortcuts

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