jsonnetfmt: Format and Check Jsonnet in CI
jsonnetfmt reformats jsonnet source to a canonical style, and with --test fails if a file is not already formatted.
A format gate keeps generated config diffs clean. jsonnetfmt is the canonical formatter and doubles as a cheap CI check.
What it does
jsonnetfmt parses jsonnet and prints it back in canonical form. -i rewrites files in place; --test does not write but exits non-zero if any file would change, which is what you run in CI. It also catches syntax errors as a side effect.
Common usage
# rewrite in place
jsonnetfmt -i config.jsonnet lib/*.libsonnet
# CI gate: fail if any file is unformatted
jsonnetfmt --test config.jsonnet lib/*.libsonnetOptions
| Flag | What it does |
|---|---|
| --test | Exit non-zero if a file is not already formatted (no write) |
| -i, --in-place | Rewrite files in place |
| -n, --indent <n> | Number of spaces for indentation |
| --string-style <d|s|l> | Preferred string quote style: double, single, leave |
| --comment-style <h|s|l> | Preferred comment style |
In CI
Run jsonnetfmt --test as a fast pre-check before the heavier jsonnet render step, so a badly formatted or unparseable file fails early. Pin the version, since a formatter change between releases can flip a passing --test to failing on untouched files.
Common errors in CI
With --test, a non-zero exit and the filename printed means the file is not canonically formatted; run jsonnetfmt -i locally to fix. A "STATIC ERROR: <file>:N:M: unexpected: ... while parsing terminal" means the source does not parse at all, so format cannot proceed; fix the syntax first.