Zig 0.16 · v0.0.2 preview

Grammar, patterns, and ownership

The fluent API is intentionally small and directional. Read a chain from project scope to subject, mood, predicate, optional dependency object, and terminal.

The pipeline

project → subject selector → should / shouldNot → predicate → dependency selector → check

files(...).inPath(...).should().dependOnFiles().inPath(...).check(...)

Selectors are available before the mood. Predicate choices are available after it. The types make invalid word orders unrepresentable instead of reporting them late.

Glob and regular-expression patterns

PatternMeaning
*Zero or more characters inside one path segment.
**Zero or more characters across path separators.
?Exactly one Unicode scalar.
[abc]One scalar in a character class.
.regex("...")An explicit regex escape hatch; regex matching is partial unless anchors say otherwise.

Glob matches are anchored to the entire candidate. Candidate and pattern separators normalize to /, while matching remains case-sensitive. A selector call with several patterns means OR; repeated selector calls mean AND.

Match targets

withName matches a filename, inFolder matches the path without its filename, inPath matches the full normalized project path, and inFile chooses exact paths. Metrics also expose Zig declaration and container identity.

Qualify with exclusions

except qualifies the selector immediately before it and inherits that selector's target. exceptTargeted names another valid target explicitly. The resulting clause is one expression:

(positive A OR positive B) AND NOT (exclusion X OR exclusion Y)

Exclusions happen before layer ownership, slice projection, and graph-query traversal. A graph query removes excluded seeds but may still reach the same node from an included seed. Calling an exclusion without a preceding selector is a stable user error.

Empty subjects fail deliberately

If the subject selector matches nothing, the rule returns EmptyTestViolation. This prevents a renamed folder from silently disabling a boundary. Set CheckOptions.allow_empty_tests only when an empty scope is an intentional policy state.

Own, clone, release

Every builder stage owns its allocator-backed filters and context. Assignment does not create another owner. Use clone before branching a chain, and call the documented deinit for every value. Returned graphs, snapshots, and violation lists also own their data.

Why this ceremony exists The API does not hide a process allocator or bind the whole fluent chain to a long-lived arena. Lifetimes remain explicit and leak checks remain meaningful in zig test.

Execution terminals

check returns an owned ViolationList. expectPasses and assertPasses turn it into Zig test behavior. Graph and metrics builders also expose owned analysis values, renderers, and filesystem exporters. Constructing the preceding stages never reads the project.

Next: Extraction & modules