Repository navigation
Conversation
|
@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
gke0op
added a commit
to gke0op/zero
that referenced
this pull request
May 18, 2026
Adds --write flag and --json envelope support to zero fmt, matching
the contract of every other Zero command.
New features:
- zero fmt --write <file> overwrites the file in place
- zero fmt --check --json emits { schemaVersion, command, mode, sourceFile, ok, unformatted }
- zero fmt --write --json emits { schemaVersion, command, mode, sourceFile, ok, written }
- --check and --write are mutually exclusive (error in both text and json modes)
- Bare zero fmt still prints to stdout (backward compat)
Text mode for --check is unchanged (fmt ok / format differs).
Closes vercel-labs#9
gke0op
added a commit
to gke0op/zero
that referenced
this pull request
May 18, 2026
Adds --write flag and --json envelope support to zero fmt, matching
the contract of every other Zero command.
New features:
- zero fmt --write <file> overwrites the file in place
- zero fmt --check --json emits { schemaVersion, command, mode, sourceFile, ok, unformatted }
- zero fmt --write --json emits { schemaVersion, command, mode, sourceFile, ok, written }
- --check and --write are mutually exclusive (error in both text and json modes)
- Bare zero fmt still prints to stdout (backward compat)
Text mode for --check is unchanged (fmt ok / format differs).
Closes vercel-labs#9
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
force-pushed
the
feat/zero-fmt-write-and-json
branch
from
August 13, 2026 16:35
7667c32 to
fe58018
Compare
fopen(..., "wb") truncated the source before writing, so an interrupted or short write lost the original file, and it wrote straight through symlinks. Use z_write_file, which writes a temp file, renames it, and refuses unsafe output paths.
This branch has not been deployed
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.