pattern

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pattern implements GitHub CODEOWNERS pattern matching.

CODEOWNERS patterns follow "most of the same rules used in gitignore files" (GitHub docs), with three documented exceptions: no `!` negation, no `[ ]` character ranges, and no `\#` escaping of a leading hash. Square brackets are literal characters. Matching is case-sensitive (S-6).

The matching logic is ported from hmarr/codeowners (match.go), MIT License, Copyright (c) 2020 Harry Marr — the actively maintained reference implementation whose semantics are differentially tested against GitHub's observed behavior. The vendored corpus in testdata/patterns.json comes from the same project. Local divergences from the port, all deliberate:

  • Compile rejects patterns starting with `!` (GitHub: negation "doesn't work"; a mutation tool must never accept or emit one).
  • Compile rejects patterns starting with `\#` (S-2/S-6: GitHub honors no `\#` escape — a line starting with `#` is always a comment, so the rule would be dead there; same standard as `!`). Only the LEADING position is special-cased: a mid-pattern `#` needs no escape at all, so `\#` after the first character keeps the oracle's literal-`#` meaning.
  • Compile rejects empty patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains added in v0.0.4

func Contains(outer, inner string) bool

Contains reports whether every path matching `inner` also matches `outer` — containment of the pattern LANGUAGES, not of their match sets over some snapshot of a file tree. Callers use it to decide whether editing a rule in place can affect anything outside an operation's scope, and a CODEOWNERS rule governs files that do not exist yet, so a tree-based answer is an accident of what happens to be committed today.

Contains is SOUND but deliberately incomplete: it never reports true for a pair where containment fails, and answers false whenever it cannot prove the containment. Callers must treat false as "unknown", not as "disjoint".

Paths are repo-relative FILE paths (see Match), so a pattern ending in `/**` is taken to require at least one further segment.

Types

type Pattern

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

Pattern is a compiled CODEOWNERS pattern.

func Compile

func Compile(patternStr string) (*Pattern, error)

Compile parses a CODEOWNERS pattern.

func (*Pattern) Match

func (p *Pattern) Match(testPath string) bool

Match reports whether the repo-relative path (forward slashes, no leading slash) matches the pattern. Paths name tracked FILES; a pattern matching a directory matches the files beneath it per the rules encoded here.

func (*Pattern) String

func (p *Pattern) String() string

String returns the original pattern text.

Jump to

Keyboard shortcuts

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