feat: zero fmt --write and --check --json envelope#9
Open
mvanhorn wants to merge 1 commit into
Open
Conversation
Add --write to overwrite the input file in place, and emit a structured
JSON envelope for --check --json (today the --json flag was ignored and
output stayed text-only). --check and --write are mutually exclusive;
bare `zero fmt` keeps current stdout behavior.
JSON shape for both modes:
{
"schemaVersion": 1,
"command": "fmt",
"mode": "check" | "write",
"sourceFile": "path",
"ok": bool,
"unformatted" | "written": [paths]
}
Matches the gofmt -l / -w and rustfmt --check / --write split, so
pre-commit hooks and editor save-on-format can call the right verb
without parsing text or shelling diff <(zero fmt file) file.
Help text and docs-site/articles/cli-reference.md updated.
|
@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
zero fmt --writeoverwrites the source file in place;zero fmt --check --jsonnow emits a structured envelope (today--jsonis ignored on--checkand output stays text-only).Why this matters
zero fmt --checkshipped earlier today and--jsonenvelopes are the contract for every other Zero command. CI pipelines and pre-commit hooks expect the gofmt -l / -w shape:--checkfor exit-code-on-diff,--writefor in-place. With neither, integrations end up shellingdiff <(zero fmt file) file(quoting risk on paths) orzero fmt file | tee file(races on large files).Demo
Changes
--writeflag overwrites the input file in place. Backward compat preserved: barezero fmtstill prints to stdout.--check --jsonnow emits{ schemaVersion, command, mode, sourceFile, ok, unformatted: [...] }.--checktext mode unchanged.--write --jsonmirrors the same shape withwritten: [...].--checkand--writeare mutually exclusive.Testing
bin/zero fmt --check examples/hello.0exits 0bin/zero fmt --check /tmp/messy.0exits 1 withformat differs: ...bin/zero fmt --check --json /tmp/messy.0emits the envelope withok: false, exits 1bin/zero fmt --write /tmp/messy.0rewrites the file, printsformatted: <path>bin/zero fmt --check --write file.0exits with the mutually-exclusive errorbin/zero fmt /tmp/messy.0(bare) still prints to stdoutLocal conformance and native:test exercise pre-existing upstream code paths that already fail on darwin-arm64 (the macho64 emitter is missing LC_UUID; binaries are rejected by dyld). The fmt code path I touched does not go through executable emission, so this PR does not change those failure modes. CI runs in the Vercel sandbox and should be green there.
AI was used for assistance.