From 335d49e90bf5de64e27e9c52229bd16350d83d13 Mon Sep 17 00:00:00 2001 From: Paolo Fabbri Date: Sat, 4 Jul 2026 23:47:58 +0100 Subject: [PATCH 1/2] build: make lint gate on gofmt, add fmt/fmt-check targets `make lint` was go vet only, so unformatted code (which CI's go vet also misses) passed clean. Add a `fmt-check` target that fails if `gofmt -l` reports anything, make `lint` depend on it, and add a `fmt` target that writes gofmt fixes. Menu, help, and .PHONY kept in sync. --- Makefile | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index c8023f3..c794d6a 100644 --- a/Makefile +++ b/Makefile @@ -25,11 +25,14 @@ menu: @printf " $(BOLD)$(GREEN)=== Testing ===$(RESET)\n" @printf " $(YELLOW)4)$(RESET) make test $(DIM)Run all tests$(RESET)\n" @printf " $(YELLOW)5)$(RESET) make test-verbose $(DIM)Run tests with verbose output$(RESET)\n" - @printf " $(YELLOW)6)$(RESET) make lint $(DIM)Run go vet$(RESET)\n" + @printf "\n" + @printf " $(BOLD)$(GREEN)=== Code Quality ===$(RESET)\n" + @printf " $(YELLOW)6)$(RESET) make fmt $(DIM)Format code with gofmt$(RESET)\n" + @printf " $(YELLOW)7)$(RESET) make lint $(DIM)Check formatting + go vet$(RESET)\n" @printf "\n" @printf " $(BOLD)$(GREEN)=== Maintenance ===$(RESET)\n" - @printf " $(YELLOW)7)$(RESET) make clean $(DIM)Remove build artifacts$(RESET)\n" - @printf " $(YELLOW)8)$(RESET) make tidy $(DIM)Tidy Go modules$(RESET)\n" + @printf " $(YELLOW)8)$(RESET) make clean $(DIM)Remove build artifacts$(RESET)\n" + @printf " $(YELLOW)9)$(RESET) make tidy $(DIM)Tidy Go modules$(RESET)\n" @printf "\n" @read -p " Enter choice: " choice; \ case $$choice in \ @@ -38,9 +41,10 @@ menu: 3) $(MAKE) run ;; \ 4) $(MAKE) test ;; \ 5) $(MAKE) test-verbose ;; \ - 6) $(MAKE) lint ;; \ - 7) $(MAKE) clean ;; \ - 8) $(MAKE) tidy ;; \ + 6) $(MAKE) fmt ;; \ + 7) $(MAKE) lint ;; \ + 8) $(MAKE) clean ;; \ + 9) $(MAKE) tidy ;; \ *) echo "Invalid choice" ;; \ esac @@ -59,7 +63,17 @@ test: test-verbose: $(GO) test -v ./... -lint: +fmt: + gofmt -w . + +fmt-check: + @if [ -n "$$(gofmt -l .)" ]; then \ + echo "These files need formatting (run 'make fmt'):"; \ + gofmt -l .; \ + exit 1; \ + fi + +lint: fmt-check $(GO) vet ./... clean: @@ -78,11 +92,13 @@ help: @printf " $(CYAN)make run$(RESET) Run with go run\n" @printf " $(CYAN)make test$(RESET) Run all tests\n" @printf " $(CYAN)make test-verbose$(RESET) Run tests with verbose output\n" - @printf " $(CYAN)make lint$(RESET) Run go vet\n" + @printf " $(CYAN)make fmt$(RESET) Format code with gofmt\n" + @printf " $(CYAN)make fmt-check$(RESET) Check formatting (fails if unformatted)\n" + @printf " $(CYAN)make lint$(RESET) Check formatting + go vet\n" @printf " $(CYAN)make clean$(RESET) Remove build artifacts\n" @printf " $(CYAN)make tidy$(RESET) Tidy Go modules\n" @printf "\n" list: help -.PHONY: menu build install run test test-verbose lint clean tidy help list +.PHONY: menu build install run test test-verbose fmt fmt-check lint clean tidy help list From 9a4764e5bb718359dc9718cf08e513a7b322327f Mon Sep 17 00:00:00 2001 From: Paolo Fabbri Date: Sun, 5 Jul 2026 00:05:18 +0100 Subject: [PATCH 2/2] build: gate lint on gofmt and enforce it in CI `make lint` was go vet only, so unformatted code (which CI's go vet also missed) passed clean everywhere. Close the gap: - Add a `fmt-check` target that fails if `gofmt -l` reports any file, make `lint` depend on it, and add a `fmt` target that writes gofmt fixes. - Point the CI workflow's lint step at `make lint` so the pipeline runs the same gofmt + vet gate as local. The Makefile is now the single source of truth; build/test stay explicit in CI (they keep -race and coverage). - Menu, help, and .PHONY kept in sync. --- .github/workflows/go.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0987c81..86449e7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -35,8 +35,8 @@ jobs: with: go-version-file: "go.mod" - - name: Vet - run: go vet ./... + - name: Lint (gofmt check + go vet) + run: make lint - name: Build run: go build -v ./...