Repository navigation
chore: add gofmt check to pre-commit hook - #343
Conversation
78cd3ef to
35e910b
Compare
Prevents gofmt violations from being committed. Runs alongside the existing dependency sync check. Install with: git config core.hooksPath hooks
35e910b to
a911079
Compare
|
Cold-review item (committed ELF binary): resolved. Same blob as #341 ( |
felixfelix-bot
left a comment
There was a problem hiding this comment.
Cold review — new findings only (1 issue previously raised about ELF binary, resolved, not repeated).
1 major:
Staged deletion of a .go file will crash the hook. git diff --cached --name-only -- '.go' includes files staged for deletion. gofmt -l tries to open the non-existent file, errors out, and because set -e is active, the script exits immediately — blocking the commit. Fix: add --diff-filter=d to exclude deletions:
git diff --cached --name-only --diff-filter=d -- '.go'
1 minor:
- Unquoted command substitution gofmt -l $(...) — filenames with spaces would break. Use xargs or while-read loop
gofmt -l received staged-but-deleted paths (--name-only includes
them), errored under set -e, and blocked the commit. Filter with
--diff-filter=d and feed gofmt one file per line via xargs -I{}
instead of unquoted command substitution (spaces-safe, no
macOS-incompatible mapfile). Functionally verified: staged deletion
+ unformatted file flags exactly the unformatted file.
Review findings: cold review 2026-08-18 (major + minor).
|
Cold-review response — major + minor fixed in
|
felixfelix-bot
left a comment
There was a problem hiding this comment.
Re-reviewed at 1eef16d: --diff-filter=d + one-file-per-line feed, verified with staged deletion, ash-portable. Resolved. Good to merge.
Fresh gofmt pass over main after the #299/#312/#327/#342/#343/#348/ #349/#351 merge wave (the wave brought new unformatted code in its wake — scanner.go struct alignment from #312, test files across modules, config_schema.go). Includes the validator.go import regrouping from the previous round of this PR (7b124b0, originally Felix's fix): stdlib and third-party groups separated with a blank line — that file came to main via #337 carrying the misgrouping. Supersedes the pre-wave branch; rebuilt fresh from current main. gofmt -l: clean across src/. Builds + tests green in touched modules (wgm, tollgate_protocol); import-paths (117) and deps-sync (125) contract checks pass.
* chore: add gofmt check to pre-commit hook
Prevents gofmt violations from being committed. Runs alongside
the existing dependency sync check.
Install with: git config core.hooksPath hooks
* fix(hooks): gofmt check survives staged deletions, spaces-safe
gofmt -l received staged-but-deleted paths (--name-only includes
them), errored under set -e, and blocked the commit. Filter with
--diff-filter=d and feed gofmt one file per line via xargs -I{}
instead of unquoted command substitution (spaces-safe, no
macOS-incompatible mapfile). Functionally verified: staged deletion
+ unformatted file flags exactly the unformatted file.
Review findings: cold review 2026-08-18 (major + minor).
---------
Co-authored-by: Amperstrand <amperstrand@localhost>
Co-authored-by: amperstand <atlas@oh-my-opencode.com>
Co-authored-by: c03rad0r <1100745+c03rad0r@users.noreply.github.com>
Extends
hooks/pre-committo also checkgofmt -lon staged.gofiles. Prevents the 16-file gofmt cleanup situation from recurring.Combined with the existing dependency sync check, the pre-commit hook now catches:
Install:
git config core.hooksPath hooksAlso recommend adding gofmt to CI (test.yml):