core/json-invariant — assert a structured file's shape
Hold a JSON file to a shape rule — like “package.json scripts must stay empty”. Parses the file properly, so formatting doesn’t matter.
What it catches
A structured config file drifting from its intended shape. The starter example: keeping package.json scripts empty so the justfile stays the single command source.
Config
rules:
justfile:
- id: no-package-scripts
use: core/json-invariant
on: "package.json"
assert: { path: scripts, keysPrefixedWith: "//" }
message: "package.json scripts must stay empty — commands live in the justfile."
| Field | What it does |
|---|---|
on |
Glob(s) for the JSON file(s) to check. |
assert.path |
A dotted path into the JSON to inspect (e.g. scripts, compilerOptions.paths). |
assert.keysPrefixedWith |
Every key at that path must start with this prefix (here, only // comment keys are allowed). Anything else is a violation. |
message |
The reason, shown on a block. |
Legal vs illegal
{ "scripts": { "//": "see justfile" } } ✓ passes
{ "scripts": { "//": "x", "dev": "vite" } } ✗ blocked: "scripts.dev"
Could this be ast-grep? Possibly — there are JSON/YAML grammars, so some structured-file checks could fold into core/ast-grep. Today core/json-invariant is the simple path for JSON; a bespoke structured-file rule (YAML, the justfile) is a small own-script until it earns a place in core.