Skip to content

REAL-WORLD-SCHEMAS-05: Custom rule: Decision must cite an alternative

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

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" })]) ] }),
]) });
  • programmatic contract(); section opts.rules
  • rule(id, fn) reading node.blocks + ctx.finding (the rules plane)