Skip to content

ci: gate gofmt in golangci-lint, add make fmt - #330

Merged
shadowbrush merged 1 commit into
mainfrom
claude/gofmt-gate
Jul 31, 2026
Merged

ci: gate gofmt in golangci-lint, add make fmt#330
shadowbrush merged 1 commit into
mainfrom
claude/gofmt-gate

Conversation

@shadowbrush

Copy link
Copy Markdown
Member

Follow-up to #329, which fixed six drifted files. This stops the drift recurring silently.

Nothing enforced formatting before: .golangci.yml had no formatters section and no workflow shelled out to gofmt, so the drift was invisible to CI.

The change

formatters:
  enable:
    - gofmt
  exclusions:
    generated: strict

Enabling the gofmt formatter makes golangci-lint run report a formatting diff as an issue and exit non-zero. That gates both make lint locally and the CI lint job — golangci-lint-action runs run by default — so no workflow change is needed.

Plus a make fmt target (golangci-lint fmt) so a failing gate has an obvious remedy, and a line in CLAUDE.md's command list.

Generated code is excluded, and I verified it

genqlient's output would otherwise be a trap: you can't hand-fix it, since make generate rewrites the file. exclusions.generated: strict keys off the standard header, which internal/api/gen/generated.go carries:

// Code generated by github.com/Khan/genqlient, DO NOT EDIT.

Injecting drift into that file:

$ gofmt -l internal/api/gen/
internal/api/gen/generated.go      # gofmt sees it
$ golangci-lint run
0 issues.                          # linter correctly ignores it

Verified end to end

clean tree            → make lint  0 issues, exit 0
inject drift          → make lint  "File is not properly formatted (gofmt)", exit non-zero
make fmt              → repairs it byte-for-byte
                      → make lint  exit 0, tree back to clean

The failure output names the file, line, and offending source line:

internal/cmdutil/memref_test.go:7:1: File is not properly formatted (gofmt)
		"acme.com:kb":   "hrn:mem:acme.com:kb",  // single colon → canonical v2
^

go test ./... — 16 packages green. make lint — 0 issues.

One thing to expect

Any in-flight branch that has drifted will start failing the lint job until it runs make fmt. main is clean as of #329, so nothing is failing now.

🤖 Generated with Claude Code

Nothing enforced formatting before this: .golangci.yml had no `formatters`
section and no workflow ran gofmt, so six files drifted unnoticed until #329.
This closes the loop so it can't recur silently.

Enabling the gofmt formatter means `golangci-lint run` reports a formatting diff
as an issue and exits non-zero — which gates both `make lint` locally and the CI
lint job (golangci-lint-action runs `run` by default), so no workflow change is
needed.

Generated code is excluded via `exclusions.generated: strict`: genqlient's
output carries the standard "Code generated by … DO NOT EDIT." header, and a
formatting complaint there isn't hand-fixable since `make generate` rewrites the
file. Verified — drift injected into internal/api/gen/generated.go is seen by
`gofmt -l` but correctly ignored by the linter.

`make fmt` (golangci-lint fmt) applies the fixes, so a failing gate has an
obvious remedy. Verified end to end: clean tree passes; injected drift fails
`make lint`; `make fmt` repairs it byte-for-byte; `make lint` passes again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@shadowbrush

Copy link
Copy Markdown
Member Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens the Go formatting contract by making gofmt enforcement part of the existing golangci-lint gate, preventing formatting drift from silently accumulating in the repo’s Go codebase.

Changes:

  • Enable the gofmt formatter in .golangci.yml so golangci-lint run fails on formatting diffs.
  • Add make fmt as the standard remediation path via golangci-lint fmt.
  • Document the new formatting gate and make fmt in CLAUDE.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
Makefile Adds a fmt target (golangci-lint fmt) and marks it phony to provide an easy fix path for formatting-gate failures.
CLAUDE.md Updates the developer command list to reflect that make lint gates gofmt and introduces make fmt.
.golangci.yml Enables the gofmt formatter and excludes generated code (generated: strict) to avoid non-actionable failures on committed generated output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@shadowbrush
shadowbrush merged commit 94ceacb into main Jul 31, 2026
5 checks passed
@shadowbrush
shadowbrush deleted the claude/gofmt-gate branch July 31, 2026 11:37
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 93681569ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

2 participants