Help us shape the future of Go! Take the 2026 Go Developer Survey

rules

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package rules loads declarative lint rules and maps typed Jev answers to deterministic decisions. Repository-provided rule files are untrusted data.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDecision = errors.New("invalid rule decision")
View Source
var ErrInvalidPack = errors.New("invalid rule pack")
View Source
var ErrInvalidRule = errors.New("invalid rule")
View Source
var ErrPackLimit = errors.New("rule pack limit exceeded")
View Source
var ErrUnsupportedSchema = errors.New("unsupported rule pack schema")

Functions

func Questions

func Questions(ctx context.Context, selections []Selection) ([]contextplan.Binding, error)

Questions copies typed criteria into planner bindings. It returns no partial result for duplicate or invalid selections.

Types

type Decision

type Decision struct {
	RuleID     string
	WorkItemID string
	Path       string
	Side       git.Side
	StartLine  int
	EndLine    int
	Severity   Severity
	Title      string
	Message    string
	Kind       string
	Value      float64
	Confidence *float64
}

Decision carries fixed rule metadata, immutable Git coordinates, and one validated numeric signal. Value is a probability for Noul/Choice and a normalized score for Score; Kind names that distinction.

func Decide

func Decide(ctx context.Context, batch contextplan.Batch, selections []Selection, response jev.Response) ([]Decision, error)

Decide validates the complete provider response before emitting any decision. selections may include other batches; only exact question IDs in batch apply.

type Pack

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

func BuiltIn

func BuiltIn() Pack

BuiltIn uses the same compiler as a repository-provided pack.

func Load

func Load(reader io.Reader) (Pack, error)

Load parses and validates one untrusted declarative rule pack.

func LoadContext

func LoadContext(ctx context.Context, reader io.Reader) (Pack, error)

LoadContext adds cancellation to bounded rule loading for CI callers.

func (Pack) Rules

func (p Pack) Rules() []Rule

Rules returns independent copies; changing them cannot alter a loaded pack.

type Rule

type Rule struct {
	ID             string
	Type           string
	Instructions   string
	NoulCriteria   *jev.NoulCriteria
	ChoiceCriteria map[string]string
	ScoreCriteria  []string
	TriggerChoices []string
	Threshold      float64
	Severity       Severity
	Title          string
	Message        string
	Paths          []string
	Sides          []git.Side
}

type Selection

type Selection struct {
	GroupID    string
	Item       git.WorkItem
	Rule       Rule
	QuestionID string
}

Selection binds one validated rule to one immutable Git work item.

func Select

func Select(ctx context.Context, pack Pack, groups []contextplan.Group) ([]Selection, error)

Select applies declarative path/side selectors in canonical item/rule order.

type Severity

type Severity string
const (
	Low      Severity = "low"
	Medium   Severity = "medium"
	High     Severity = "high"
	Critical Severity = "critical"
)

Jump to

Keyboard shortcuts

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