validation

package
v0.0.0-...-072aef6 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package validation provides custom validation rule checking for entities. It encapsulates the logic for evaluating metamodel validation rules against entity sets, supporting scoped validation for view-based analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckChecklistRule

func CheckChecklistRule(items []markdown.ChecklistItem, rule *metamodel.ChecklistRule) bool

CheckChecklistRule validates checklist items against a metamodel checklist rule. Returns true when items are acceptable (or when rule is nil, or when there are no items).

func CheckContentRule

func CheckContentRule(content string, rule *metamodel.ContentRule) bool

CheckContentRule validates markdown content against a metamodel-defined content rule. Returns true if the content satisfies the rule (or when rule is nil).

func CountBySeverity

func CountBySeverity(violations []Violation) (errors, warnings int)

CountBySeverity returns counts of errors and warnings from violations.

Types

type LuaViolation

type LuaViolation struct {
	Message  string // Custom error message (required)
	Severity string // "error" or "warning" (optional, defaults to rule's severity)
}

LuaViolation represents a violation returned from a Lua validation script.

type Service

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

Service validates entities against custom metamodel rules.

func New

func New(meta *metamodel.Metamodel, deps lua.ReadDeps) *Service

New creates a validation service for the given metamodel. deps provides read-only lua access for rules that use Lua scripts. The ProjectRoot field of deps is used to resolve lua_file paths from validations/. The supplied metamodel is authoritative — it overwrites deps.Meta so the Go-side rule evaluator and the Lua-side filter helpers cannot disagree about which schema is in effect.

func (*Service) Check

func (s *Service) Check(entities []*entity.Entity, scope map[string]bool) []Violation

Check runs all validation rules against the given entities. If scope is non-nil, only entities in scope are checked.

func (*Service) CheckRule

func (s *Service) CheckRule(
	rule metamodel.ValidationRule,
	entities []*entity.Entity,
	scope map[string]bool,
) []Violation

CheckRule checks a single rule against entities.

func (*Service) CheckRules

func (s *Service) CheckRules(entities []*entity.Entity, scope, ruleNames map[string]bool) []Violation

CheckRules runs validation rules against the given entities. If ruleNames is nil, all rules are run. Otherwise, only rules in the set are run. If scope is non-nil, only entities in scope are checked.

func (*Service) Rules

func (s *Service) Rules() []metamodel.ValidationRule

Rules returns the validation rules from the metamodel.

func (*Service) WithCache

func (s *Service) WithCache(c *lua.Cache) *Service

WithCache wires a shared Lua cache into validation runs so rela.cache.* inside validation scripts is functional and namespaced per-rule. Zero-or-nil cache leaves validation runtimes un-cached.

type Violation

type Violation struct {
	RuleName    string
	Description string
	Severity    string // "error" or "warning"
	EntityID    string
	EntityTitle string
}

Violation represents a custom validation rule violation.

Jump to

Keyboard shortcuts

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