Documentation
¶
Overview ¶
Package filter provides generic attribute-based filtering of requirements using expr-lang/expr as the evaluation engine.
A filter expression is compiled once at startup into bytecode, then evaluated against each requirement's attribute map. The evaluation context exposes every attribute from the req's attr block plus the built-in variables `id` and `title` (and the RFC built-in attributes `status`, `disposition`, `trace`, `version`, which resolve to nil when a requirement does not declare them).
Compile-time validation rejects expressions that reference attribute names not declared in any document's schema.yaml (a global typo check), and reports expr syntax errors once before any requirement is evaluated.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildFoundAttrs ¶
BuildFoundAttrs computes the union of every attribute key actually present on some requirement in the tree, whether or not it is declared in a schema.yaml. Relaxed filtering unions this with BuildValidAttrs so undeclared-but-present attributes can be filtered.
func BuildValidAttrs ¶
BuildValidAttrs computes the union of all schema property names across every document plus the built-in variable names. The result is used by Compile for strict attribute validation.
func WriteWarnings ¶
WriteWarnings writes relaxed-mode filter warnings to w, one per line, prefixed with "reqmd: warning: ". It is a no-op when warnings is empty so callers can invoke it unconditionally.
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter is a compiled attribute filter expression. It is safe for concurrent use after construction — the underlying vm.Program is read-only.
func Compile ¶
Compile parses, validates, and compiles a filter expression (strict mode).
validAttrs is the union of all schema property names (plus built-in variable names) across every document in the tree. Referencing a name not in this set is a compile-time ERROR — this catches typos and references to attributes that no document declares.
The expression is compiled with AllowUndefinedVariables so that a requirement whose document does not declare a referenced attribute evaluates that variable to nil (the req is excluded unless the expression handles absence, e.g. `variant == null`).
func CompileForDocs ¶
func CompileForDocs(docs []model.Document, expr string, allowUndeclared bool) (*Filter, []string, error)
CompileForDocs compiles an expression against the attribute union of the given documents. It is the shared entry point for every CLI command that accepts a --filter flag: Compile + BuildValidAttrs in one call.
When allowUndeclared is false the strict typo check applies and any reference to an attribute not declared in a schema.yaml is an error. When true, references to attributes found on any requirement are allowed (undeclared-but-present) and every out-of-schema reference is returned as a warning instead of an error. Returns (nil, nil, nil) when expr is empty.
func CompileRelaxed ¶
func CompileRelaxed(exprStr string, validAttrs, declaredAttrs map[string]struct{}) (*Filter, []string, error)
CompileRelaxed compiles a filter expression without hard-failing on attribute names that are not declared in any schema.yaml. validAttrs is the expanded allowed set (schema-declared names plus every attribute actually found on a requirement); declaredAttrs is the schema-declared set plus built-ins and drives which references produce a warning. Every referenced name outside declaredAttrs yields a warning instead of an error, so undeclared-but-present attributes become filterable while true typos no longer abort the run.
func (*Filter) FilterDocs ¶
FilterDocs returns a new []model.Document containing only matching requirements per document. Non-requirement nodes (containers and info items) are always kept, so document structure and content survive filtering. Documents with all requirements filtered out are kept (with only items) so document-level structure is preserved for list/stats/ export output.
func (*Filter) Match ¶
Match evaluates the compiled expression against a single requirement. Returns (true, nil) if the requirement matches, (false, nil) if not, and (false, err) if evaluation fails (e.g. type mismatch).
func (*Filter) MatchingIDs ¶
MatchingIDs returns a set of requirement IDs that match the filter. Used by check/serve for filter-aware graph checks — the graph is built from the full tree, but only matching reqs are checked/reported.