Skip to content

Check formatting before the commit, not after the push - #15

Merged
teceer merged 1 commit into
mainfrom
chore/pre-commit-hooks
Aug 7, 2026
Merged

teceer merged 1 commit into
mainfrom
chore/pre-commit-hooks

Conversation

@teceer

@teceer teceer commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Formatting has landed on main and turned the lint job red three times — twice around #5 (on code from #3 and #4), and again yesterday in #14. The pattern never changes: rustfmt is enforced in CI and run nowhere else, so it is found after landing, by whoever pushes next.

What this adds

  • .githooks/pre-commit — formatting check on staged files
  • make hooks — points core.hooksPath at .githooks/, so hooks are versioned and change with the repo instead of being copied into .git once and forgotten
  • make fmt — the other half: whatever the hook rejects, this fixes

The design constraint

It checks formatting and nothing else. make lint runs clippy, golangci-lint and credo across nine services. A hook people wait thirty seconds for is a hook people pass --no-verify to, and then it protects nothing.

Each language is checked only when a file of that language is staged — the two slow starts here are the BEAM and cargo, and neither should be paid for a change that did not touch them. Go is checked per file (gofmt needs no project context); Rust and Elixir per project, because rustfmt run per file needs the edition passed by hand and getting that wrong silently formats to the wrong rules.

The failure output names the check and both ways out:

  commit blocked — formatting:

    go        gofmt: services/world-gateway/internal/economy/probe_bad.go

  fix:  make fmt
  skip: git commit --no-verify

Two deliberate omissions

No buf format. I tried it and backed it out: it reflows .proto comments onto a single space before the slashes, destroying the column alignment those files use deliberately —

-  string event_id = 1;                          // UUIDv7, deduplication key
-  uint64 tick = 2;                              // simulation tick, the ordering authority
+  string event_id = 1; // UUIDv7, deduplication key
+  uint64 tick = 2; // simulation tick, the ordering authority

That is a style choice by whoever wrote those files, and a hook is the wrong place to overrule it. make proto-lint already runs buf lint and buf breaking, which catch the mistakes that actually matter.

No mix format for a service without a .formatter.exs — broadcast is still an empty shell (ADR 0010), and mix format errors out rather than no-opping there.

Found while testing it

gofmt immediately flagged a stray blank line in driver.go, from my own #10. golangci-lint does not have gofmt enabled in this repo, so CI never saw it. Fixed here.

Test plan

  • Hook installed via make hooks; a deliberately malformed .go file is rejected with the message above
  • make fmt then makes the same commit pass
  • make fmt is idempotent on a clean tree — running it twice changes nothing
  • make help lists both new targets
  • Not covered: the Rust and Elixir paths are exercised by construction but were not driven with a deliberately broken file, since both check a whole project rather than a file

What this does not solve

Nothing in CI builds the Docker images, which is how the go.work drift in #11 went unnoticed until I built them by hand. Different problem, same shape — worth its own decision.

🤖 Generated with Claude Code

Formatting has landed on main and turned the lint job red three times now
(twice around #5, again in #14). The pattern never changes: rustfmt is
enforced in CI and run nowhere else, so it is found after landing, by
whoever pushes next.

`make hooks` points core.hooksPath at .githooks/, so the hooks are
versioned and change with the repo rather than being copied into .git once
and forgotten.

The hook checks formatting and nothing else. `make lint` runs clippy,
golangci-lint and credo across nine services; a hook people wait thirty
seconds for is a hook people pass --no-verify to, and then it protects
nothing. Each language is checked only when a file of that language is
staged, because the two slow starts are the BEAM and cargo and neither
should be paid for a change that did not touch them.

`make fmt` is the other half: whatever the hook rejects, it fixes.

Two deliberate omissions:

- No `buf format`. It reflows .proto comments onto a single space before
  the slashes, which destroys the column alignment several of those files
  use to keep a field's meaning readable next to its number. That is the
  author's style choice and a hook is the wrong place to overrule it —
  `make proto-lint` already covers the checks that catch real mistakes.
- No `mix format` for a service without a .formatter.exs, since broadcast
  is still an empty shell (ADR 0010).

Also fixes what gofmt immediately found: a stray blank line in driver.go,
from #10. golangci-lint does not have gofmt enabled here, so CI never saw
it.
@teceer
teceer merged commit 45635ee into main Aug 7, 2026
7 checks passed
@teceer
teceer deleted the chore/pre-commit-hooks branch August 7, 2026 12:31
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