Documentation
¶
Overview ¶
Package rules implements declarative, layered content rules.
Index ¶
- func Applies(rule CompiledRule, target string) bool
- func DifferingKeys(a, b RuleSpec) []string
- func IsDirConfigPath(target string) bool
- func IsStdlib(name string) bool
- func Matches(spec RuleSpec, rel string) bool
- func PackageOf(member string) string
- func Register(member Member)
- func SortDiagnostics(d []validation.Diagnostic)
- func Unify(layers []Layer) (map[string]UnifiedRule, error)
- func WriteDoc(w io.Writer, manifest Manifest)
- func WriteList(w io.Writer, members []Member)
- type BundleRootError
- type Check
- type CompiledRule
- type Defaults
- type Engine
- func (e *Engine) AdmitLeaf(ctx context.Context, leaf vfs.Change, actor string, ...) error
- func (e *Engine) CheckConfigFile(ctx context.Context, dir string, content []byte) error
- func (e *Engine) Effective(ctx context.Context, target string) ([]CompiledRule, error)
- func (e *Engine) Invalidate(dir string)
- func (e *Engine) OnMove(ctx context.Context, from, to string) error
- func (e *Engine) OnRemove(ctx context.Context, target, actor string) error
- func (e *Engine) OnWrite(ctx context.Context, target string, content []byte, actor string) error
- func (e *Engine) PreApplyLeaf(ctx context.Context, leaf vfs.Change, actor string, ...) error
- func (e *Engine) ValidateBundle(ctx context.Context, fsys vfs.FileSystem, root string) ([]validation.Diagnostic, error)
- func (e *Engine) ValidateFile(ctx context.Context, fsys vfs.FileSystem, bundleRoot, target string, ...) []validation.Diagnostic
- func (e *Engine) Validator() validation.Validator
- type Env
- type FileConfig
- type Finding
- type FolderLayerSource
- type Kind
- type Layer
- type LayerSource
- type Manifest
- type Member
- type Mode
- type Options
- type Param
- type ParamType
- type Registry
- type Rejection
- type RuleSpec
- type Scope
- type Subject
- type UnificationError
- type UnifiedRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Applies ¶
func Applies(rule CompiledRule, target string) bool
func DifferingKeys ¶
DifferingKeys returns normalized semantic fields that differ between specs.
func IsDirConfigPath ¶
func SortDiagnostics ¶
func SortDiagnostics(d []validation.Diagnostic)
Types ¶
type BundleRootError ¶
BundleRootError reports that validation was requested above independently governed docsets. Running bundle rules there would silently choose the wrong configuration boundary.
func (*BundleRootError) Error ¶
func (e *BundleRootError) Error() string
type CompiledRule ¶
type CompiledRule struct {
Name string
Spec RuleSpec
Origins []string
Scope string
Member Member
Check Check
}
func Compile ¶
func Compile(reg *Registry, env func(string) Env, unified map[string]UnifiedRule) ([]CompiledRule, error)
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) CheckConfigFile ¶
CheckConfigFile validates a proposed .lore/config.yaml against every layer above its containing directory.
func (*Engine) Invalidate ¶
Invalidate drops cached folder layers at and below dir.
func (*Engine) PreApplyLeaf ¶
func (*Engine) ValidateBundle ¶
func (e *Engine) ValidateBundle(ctx context.Context, fsys vfs.FileSystem, root string) ([]validation.Diagnostic, error)
func (*Engine) ValidateFile ¶
func (e *Engine) ValidateFile(ctx context.Context, fsys vfs.FileSystem, bundleRoot, target string, content []byte) []validation.Diagnostic
func (*Engine) Validator ¶
func (e *Engine) Validator() validation.Validator
type FileConfig ¶
type FileConfig struct {
Version int `yaml:"version"`
Rules map[string]RuleSpec `yaml:"rules,omitempty"`
Packages map[string]any `yaml:"packages,omitempty"`
Hooks map[string]any `yaml:"hooks,omitempty"`
Operations map[string]any `yaml:"operations,omitempty"`
}
FileConfig is the strictly decoded contents of a folder's .lore/config.yaml file.
func DecodeFile ¶
func DecodeFile(content []byte) (FileConfig, error)
DecodeFile decodes a folder rule configuration. Reserved sections are accepted while empty so configurations remain forward-compatible.
type FolderLayerSource ¶
type FolderLayerSource interface {
LayersForDir(context.Context, string) ([]Layer, error)
LayersAbove(context.Context, string) ([]Layer, error)
Invalidate(string)
}
FolderLayerSource additionally supports validating a proposed folder config without reading the current config in that same folder.
type LayerSource ¶
type Member ¶
func PackageMembers ¶
PackageMembers returns the registered members beneath a package path.
type Options ¶
type Options struct {
Registry *Registry
Config LayerSource
Folders FolderLayerSource
Env func(string) Env
Logger *slog.Logger
}
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func DefaultRegistry ¶
func DefaultRegistry() *Registry
func NewRegistry ¶
func NewRegistry() *Registry
type Rejection ¶
type RuleSpec ¶
type RuleSpec struct {
Match []string `yaml:"match" json:"match"`
Exclude []string `yaml:"exclude,omitempty" json:"exclude,omitempty"`
Use string `yaml:"use" json:"use"`
With map[string]any `yaml:"with,omitempty" json:"with,omitempty"`
Enforce *bool `yaml:"enforce,omitempty" json:"enforce,omitempty"`
Default bool `yaml:"default,omitempty" json:"default,omitempty"`
}
func (RuleSpec) Equal ¶
Equal compares normalized rule semantics. In particular, an omitted enforce value is equal to enforce: true and nil/empty collections are equivalent.
func (RuleSpec) IsEnforcing ¶
type UnificationError ¶
type UnificationError struct {
Rule string
OuterOrigin string
InnerOrigin string
DifferingKeys []string
}
func (*UnificationError) Error ¶
func (e *UnificationError) Error() string
type UnifiedRule ¶
UnifiedRule retains the declaring scope while layers are unified. Child declarations may refine a rule, but identical declarations do not move the outer declaration's relative glob root.