rules

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rules reads a repository's vx.toml: what text merges cannot see.

[[unique]]      files matching glob may not share a key, e.g. two
                migrations with the same number
[[generated]]   files matching glob are generated by command: vx never
                text-merges them and tells people to regenerate
[checks]        required = commands vx land should run (--run)

The package is pure: it reads trees and blobs through a blob.Store, so the server (land, ship, rebase) and the CLI (vx sync, vx land) apply the same rules to the same trees.

Index

Constants

View Source
const File = "vx.toml"

File is where a repository keeps its rules: the root of the tree.

View Source
const WarningRule engine.WarningKind = "rule"

WarningRule marks a warning about a vx.toml rule.

Variables

This section is empty.

Functions

func Check

func Check(ctx context.Context, s blob.Store, r Rules, base, tree hash.Hash) ([]engine.Warning, error)

Check reports [unique] violations in tree as warnings of kind WarningRule, limited to keys used by a file that is new or changed between base and tree, so a clash that predates the change is not repeated on every land. base may be zero: every file counts as new.

Each warning has Name = the rule name, Decl = the shared key, Files = the full paths of every file using it (sorted), Path = the first of them that changed, and a Detail for people:

migration 008 is used by 008_effort_rebases.sql and 008_orgs.sql (rule migration in vx.toml)

func Files

func Files(ctx context.Context, s blob.Store, tree hash.Hash, g Glob) ([]string, error)

Files lists the files of tree that match g, sorted. Only the glob's literal directory is read.

func KeyOf

func KeyOf(key *regexp.Regexp, path string) (string, bool)

KeyOf returns the first group of key matched against the base name of path.

func MatchGlob

func MatchGlob(pattern, path string) bool

MatchGlob reports whether path matches pattern; an invalid pattern matches nothing.

func MergeOptions

func MergeOptions(ctx context.Context, s blob.Store, trees ...hash.Hash) []engine.MergeOption

MergeOptions are the engine options of a merge whose sides are trees: the [[generated]] rules of every one of them, so a generated file is never text-merged whichever side declared it. A vx.toml that does not parse adds nothing (the land reports it).

func MissingChecks

func MissingChecks(r Rules, ran []string) []string

MissingChecks returns the required checks of r that are not in ran (commands vx ran, compared after trimming spaces), in vx.toml order.

func NotVerified

func NotVerified(command string) string

NotVerified describes a required check vx did not run:

required check `go vet ./...` (vx.toml) was not run by vx

Types

type Error

type Error struct {
	Problems []Problem
}

Error lists everything wrong in a vx.toml.

func (*Error) Error

func (e *Error) Error() string

type Generated

type Generated struct {
	Glob    string
	Command string
}

Generated says files matching Glob are generated by Command: vx never text-merges them and tells people to regenerate instead.

type Glob

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

Glob matches slash-separated repository paths. A "*" matches any run of characters within one path segment, "?" one character within a segment, and a "**" segment any number of segments (zero or more):

internal/store/migrations/*.sql   files directly in that directory
gen/**                            every file under gen/
**/*_string.go                    a file of that name at any depth
api/**/types.go                   api/types.go, api/v1/types.go, ...

Paths have no leading slash. Character classes and braces are not supported, so a glob means the same thing to everyone reading vx.toml.

func CompileGlob

func CompileGlob(pattern string) (Glob, error)

CompileGlob checks a glob and prepares it for matching. Errors say what is wrong and how to write it instead.

func (Glob) Dir

func (g Glob) Dir() string

Dir is the literal directory every matching path lives under, "" for the repository root: the part of the tree a scan has to read.

func (Glob) Match

func (g Glob) Match(path string) bool

Match reports whether path matches the glob.

func (Glob) String

func (g Glob) String() string

String returns the glob as written.

type Problem

type Problem struct {
	Line int // 1-based; 0 when the line is not known
	Msg  string
}

Problem is one thing wrong in vx.toml.

func (Problem) String

func (p Problem) String() string

type Rules

type Rules struct {
	Unique         []Unique
	Generated      []Generated
	RequiredChecks []string
	Source         string // e.g. "vx.toml at 3f2a1c9d0e7b"; empty: none
}

Rules are a repository's vx.toml.

func At

func At(ctx context.Context, s blob.Store, tree hash.Hash) (Rules, error)

At returns the rules in vx.toml at the root of tree. Without a vx.toml there are no rules and no error. Source says where they came from.

func Parse

func Parse(data []byte) (Rules, error)

Parse parses vx.toml. Syntax errors, unknown keys, invalid globs and regular expressions are errors (*Error) that say the line and what is wrong.

func (Rules) GeneratedMatcher

func (r Rules) GeneratedMatcher() func(path string) (command string, ok bool)

GeneratedMatcher compiles the [[generated]] globs once. The returned function reports whether path is generated and by which command (the first matching rule wins). Invalid globs match nothing.

func (Rules) IsEmpty

func (r Rules) IsEmpty() bool

IsEmpty reports whether there are no rules.

func (Rules) UniqueRule

func (r Rules) UniqueRule(name string) (Unique, bool)

UniqueRule returns the [unique] rule called name.

type Unique

type Unique struct {
	Name string
	Glob string
	Key  string
}

Unique says that files matching Glob may not share the first group of Key, matched against the file's base name (for example two migrations with the same number).

Jump to

Keyboard shortcuts

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