REAL-WORLD-SCHEMAS-05: Custom rule: Decision must cite an alternative
What it demonstrates
Section titled “What it demonstrates”A node-local rule() emitting a finding when a section’s prose lacks a required reference.
Builds on: REAL-WORLD-SCHEMAS-03: Typed table inside Consequences
How it’s done
Section titled “How it’s done”A TypeScript program against the library API; inline comments show the resulting values and behavior.
import { contract, sections, section, rule } from "markdown-contract";const adr = contract({ body: sections({ order: "strict" }, [ section("Decision", { rules: [ rule("adr/cites-alternative", (node, ctx) => /alternativ/i.test(node.blocks.map(b => b.kind === "paragraph" ? b.text : "").join(" ")) ? [] : [ctx.finding({ id: "adr/cites-alternative", level: "error", message: "Decision must reference an alternative" })]) ] }),]) });Surfaces exercised
Section titled “Surfaces exercised”programmatic contract(); section opts.rulesrule(id, fn) reading node.blocks + ctx.finding (the rules plane)