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 ./... 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