Skip to content

VALIDATION-PLANES-15: A cross-cutting docRule over the whole doc

docRule(id, fn) sees the typed Doc (frontmatter and body together) to enforce relationships no single plane can.

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

A TypeScript program against the library API; inline comments show the resulting values and behavior.

import { docRule } from "markdown-contract";
const c = contract({
frontmatter: z.object({ status: z.enum(["open", "closed"]) }),
body: sections({}, [section("Goal")]),
rules: [
docRule("task/closed-needs-note", (doc, ctx) =>
doc.frontmatter.status === "closed" && !doc.body.section("Completion")
? [ctx.finding({ id: "task/closed-needs-note",
message: "closed tasks need a Completion section" })] : []),
],
});
  • docRule() / ContractDef.rules (src/core/grammar.ts)
  • Doc.frontmatter + Doc.body.section() in one rule (src/core/model.ts)
  • rule plane (runDocRules in src/core/validate.ts)