Skip to content

chore: zig fmt the tracked Zig sources - #656

Merged
xiaods merged 1 commit into
mainfrom
chore/zig-fmt
Oct 19, 2026
Merged

xiaods merged 1 commit into
mainfrom
chore/zig-fmt

Conversation

@xiaods

@xiaods xiaods commented Oct 19, 2026

Copy link
Copy Markdown
Owner

纯格式化 PR:对 main 上被 zig fmt --check 报出来的 9 个已跟踪 Zig 文件跑一遍 zig fmt,不改任何其他东西。

范围

build.zig
sandboxd/src/events.zig
sandboxd/src/transcript.zig
sandboxd/src/files.zig
sandboxd/src/execctl.zig
sandboxd/src/watch.zig
sandboxd/src/processes.zig
sandboxd/src/transcript_test.zig
tandem/src/storage/rqlite.zig

共 9 个文件、22 增 43 删,体量很小,便于 review。

有一个被报出来的文件故意不动:tandem/zig-pkg/libxev-*/src/bench/ping-pongs.zig 位于依赖缓存目录里(.gitignore 的 /tandem/zig-pkg 已排除),既未被 git 跟踪,也不属于我们该改的第三方代码。

如何证明「只动了空白」

git diff -w 在这里不能作为证据——zig fmt 重排了换行(比如把三行的 inotify_add_watch(...) 合成一行),行内容变了但 token 没变。

所以我对每个文件做了 token 级比对:把改动前后的内容去掉所有空格、tab、换行后逐字节比较。

IDENTICAL (whitespace-only): build.zig
IDENTICAL (whitespace-only): sandboxd/src/events.zig
IDENTICAL (whitespace-only): sandboxd/src/transcript.zig
IDENTICAL (whitespace-only): sandboxd/src/files.zig
IDENTICAL (whitespace-only): sandboxd/src/execctl.zig
IDENTICAL (whitespace-only): sandboxd/src/watch.zig
IDENTICAL (whitespace-only): sandboxd/src/transcript_test.zig
IDENTICAL (whitespace-only): sandboxd/src/processes.zig
IDENTICAL (whitespace-only): tandem/src/storage/rqlite.zig

9/9 完全一致 → 没有任何表达式、字符串字面量或运算符发生变化。

验证

项目 结果
zig build sandboxd ✅ 三个 musl 目标全部构建通过
zig fmt --check build.zig sandboxd/src/*.zig ✅ 0 个文件再被报
sandboxd 单元测试 ✅ 改动前后同样 12 个既有失败,按名称逐一相同

那 12 个失败是既有的(PTY 测试 + readAllFromFdTrunc 的 1 MiB 越界,都是 Linux 侧、与格式化无关),与格式化无关,未在本次范围内处理。

为什么现在做

配合 #655:那个 PR 改了 build.zig(把静态链接限制为 Linux-only),如果不先格式化,build.zig 就会带着不合规状态进去。保持树干净,下一个真正的改动也好 review。

需要说明的是两个 PR 都动 build.zig:本 PR 是纯对齐调整,#655 是在 buildVersionFlags 里加参数。改动区域不同,rebase 时 git 应能自动解决;如果冲突我会先 rebase 本 PR。

`zig fmt --check` reported nine tracked files out of conformance. This runs
zig fmt over them, changing nothing else.

Scope

  build.zig
  sandboxd/src/events.zig, transcript.zig, files.zig, execctl.zig,
               watch.zig, processes.zig, transcript_test.zig
  tandem/src/storage/rqlite.zig

One reported path is deliberately left alone:
tandem/zig-pkg/libxev-*/src/bench/ping-pongs.zig sits inside the fetched
dependency cache (gitignored via /tandem/zig-pkg), so it is neither tracked nor
ours to reformat.

Verification

Every file is whitespace-only at the token level: stripping all spaces, tabs
and newlines from the old and new content yields identical bytes, per file. So
no expression, string or operator moved.

  - zig build sandboxd  -> all three musl targets build
  - zig fmt --check     -> clean for build.zig and sandboxd/src/*.zig
  - sandboxd unit tests -> the same 12 pre-existing failures before and after,
    identical by name (PTY tests plus a readAllFromFdTrunc 1 MiB off-by-one,
    both unrelated to formatting and all Linux-side)

Needed because an earlier change to build.zig (making static linking
Linux-only) would otherwise ship with an unformatted build.zig; a clean tree
also keeps the next real edit reviewable.
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

977 tests  ±0   950 ✅ ±0   6m 52s ⏱️ +4s
120 suites ±0    27 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit e6fe1cc. ± Comparison against base commit 5538029.

@xiaods
xiaods merged commit 6887a5c into main Oct 19, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant