Skip to content

VALIDATION-PLANES-14: A custom node rule with its own level

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

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)
  • 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)