Skip to content

VALIDATION-PLANES-02: The smallest contract: one required section

contract({body: sections([section(…)])}).validate(src) emits a single structure-plane Finding for a missing section.

Builds on: VALIDATION-PLANES-01: Parse markdown into a DocTree

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

import { contract, sections, section } from "markdown-contract";
const c = contract({ body: sections({}, [section("Summary")]) });
const { findings } = c.validate("## Overview\n", { path: "doc.md" });
// findings[0] = { id: "structure/section-missing", level: "error",
// path: "doc.md", message: "required section 'Summary' is missing" }
  • contract() / sections() / section() (src/core/grammar.ts)
  • Contract.validate() (src/core/validate.ts)
  • structure/section-missing (src/core/structure.ts)
  • Finding {id, level, path, message} (src/core/finding.ts)