Skip to content

gofmt the tree, and make staying formatted automatic - #4

Merged
ptinsley merged 3 commits into
mainfrom
gofmt-cleanup
Aug 5, 2026
Merged

ptinsley merged 3 commits into
mainfrom
gofmt-cleanup

Conversation

@ptinsley

@ptinsley ptinsley commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Why

main.go had drifted out of gofmt compliance and nothing in the build fails over it, so it stayed that way silently. This formats it, writes down the convention, and then makes the convention mechanical so it does not depend on anyone remembering.

1. The formatting sweep (f846523)

Only main.go was affected — 26 lines, no behaviour change:

  • one out-of-order import (kingpin sorted after google.golang.org/api/option)
  • gofmt's //Comment → // Comment rule, which has applied since Go 1.19 and accounts for all but one line of the diff

Kept as its own commit so it never has to be read alongside a real change. gofmt -l . now prints nothing.

2. CLAUDE.md (ce41922)

The repo had no CLAUDE.md. Formatting leads, since that is what prompted this: run gofmt -w . before every commit, and keep a formatting sweep out of a behaviour change so the substantive diff stays readable.

It also records the decisions from #3 that are cheap to undo by accident and expensive to rediscover:

  • the emulator tests must never become skippable — a green run that quietly tested nothing is worse than a red one
  • every wait in the integration suite is a bounded assertion, not a sleep
  • fixture setup belongs before fling starts and appends after, because that split is what the read_from_beginning and tail-mode scenarios exist to test
  • there is one go.mod on purpose

3. The gofmt hook (963539e)

A written convention only works when someone remembers it. .claude/settings.json adds a PostToolUse hook so that after any Write/Edit/MultiEdit, .go files are formatted in place.

Guards on the .go suffix, and cannot fail a tool call — a missing path or a gofmt error is swallowed.

Verified by piping the exact stdin payload the hook receives:

Input Result
misformatted .go file corrected (func F( ) int → func F() int)
.txt file skipped, unmodified
empty path clean exit

Then verified end-to-end in a live session: a deliberate func lineTimeAt(offset int) written through Edit came back correctly formatted, with git diff empty.

Note for reviewers: the hook does not take effect in a session that was already running when .claude/settings.json first appeared — the settings watcher only monitors directories that had a settings file at startup. Open /hooks once, or start a new session.

Limits worth knowing

The hook only fires on Write/Edit/MultiEdit. A .go file produced by a script or a go command will not trigger it, which is why CLAUDE.md still asks for a gofmt -l . check before committing rather than treating the hook as complete coverage.

Verification

gofmt -l . empty, go build, go vet, and go test ./... all clean — 30 tests, 42 subtests, 10 emulator scenarios.

🤖 Generated with Claude Code

ptinsley and others added 3 commits August 5, 2026 13:46
No behaviour change. One out-of-order import, and the //Comment -> //
Comment spacing gofmt has wanted since Go 1.19, which accounts for all but
one line of the diff.

Kept apart from any substantive change so this never has to be read.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Formatting first, since that is what prompted this: gofmt before every
commit, and keep a formatting sweep out of a behaviour change so the real
diff stays readable.

Also records the decisions from the test consolidation that are easy to
undo by accident: the emulator tests must never be made skippable, every
wait is a bounded assertion rather than a sleep, fixture setup belongs
before startup and appends after, and there is one go.mod on purpose.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
CLAUDE.md asks for gofmt before every commit, but a written convention only
works when someone remembers it. This makes it mechanical: after any
Write/Edit/MultiEdit, .go files are formatted in place.

Guards on the .go suffix so non-Go edits are untouched, and cannot fail a
tool call - a missing path or a gofmt error is swallowed.

Verified by piping the hook payload for a misformatted .go file (fixed), a
.txt file (skipped), and an empty path (clean exit).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ptinsley
ptinsley merged commit 3e73d9f into main Aug 5, 2026
@ptinsley
ptinsley deleted the gofmt-cleanup branch August 5, 2026 18:52
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

⌂ 换网址