VALIDATION-PLANES-14: A custom node rule with its own level
What it demonstrates
Section titled “What it demonstrates”rule(id, fn) attached via SectionOpts.rules runs on its bound section node and mints a finding at a level it chooses.
Builds on: VALIDATION-PLANES-02: The smallest contract: one required section
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 { rule } from "markdown-contract";
const c = contract({ body: sections({}, [ section("Goal", { rules: [ rule("goal/non-empty", (node, ctx) => node.blocks.length ? [] : [ctx.finding({ id: "goal/non-empty", level: "warn", message: "Goal has no body", pos: node.pos })]), ] }),]) });// (Finding.fix is an optional descriptor on the finding shape for repair tools)Surfaces exercised
Section titled “Surfaces exercised”rule() / SectionOpts.rules (src/core/grammar.ts, run in src/core/structure.ts)ctx.finding level/pos (src/core/registry.ts)Finding.fix (optional descriptor) (src/core/finding.ts)