Check Markdown before every commit
Copy-paste hooks for pre-commit, lint-staged, husky, and lefthook that check the Markdown a commit stages.
The airlock does not argue. It checks the seal before the door opens, not after.
Prompt for your coding agentOpen in Claude ↗
Add mediva to this repo (npm i -D mediva) and a pre-commit hook that runs npx --no-install mdv check --staged, so staged Markdown is checked against its contracts before every commit.
npx --no-install mdv check --staged| Flag | Why it suits a hook |
|---|---|
--staged | checks the staged documents, read from the git index, so unstaged edits never leak in |
| explicit files with no contract | the lint gate only, plus a no-contract warning; fail only on lint |
pre-commit
repos:
- repo: https://github.com/jamespacileo/mediva-public
rev: main # pin a release tag; `pre-commit autoupdate` does it for you
hooks:
- id: mdvOr, with the mdv already in your devDependencies:
repos:
- repo: local
hooks:
- id: mdv
name: mdv check
entry: npx --no-install mdv check
language: system
files: \.md$lint-staged
{
"lint-staged": {
"*.md": "mdv check"
}
}husky
npx --no-install mdv check --stagedlefthook
pre-commit:
commands:
mdv:
run: npx --no-install mdv check --stagedVariations
| Want | Do |
|---|---|
| a quieter rule | rules: { "too-few-words": "warn" } (What blocks) |
| the whole branch, not one commit | mdv check --new |