diff --git a/.golangci.yml b/.golangci.yml --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,8 @@ linters: enable: - gofmt # Enforce standard Go formatting + - gofumpt # Stricter gofmt (extra formatting rules) + - goimports # Check import organization - govet # Examine Go source code and report suspicious constructs - errcheck # Check for unchecked errors - staticcheck # Advanced static analysis @@ -10,11 +12,19 @@ - ineffassign # Detect ineffectual assignments - typecheck # Standard Go type checker linters-settings: + gofmt: + simplify: true # Simplify code where possible + + gofumpt: + extra-rules: true # Enable extra formatting rules + errcheck: - check-blank: true # Check for blank error assignments (x, _ = f()) + check-blank: false # Don't check blank assignments (allows _ = in defer closures) govet: enable-all: true + disable: + - shadow # Disable shadow checking (common pattern in tests) staticcheck: checks: ["all"] @@ -27,3 +37,6 @@ issues: exclude-use-default: false max-issues-per-linter: 0 max-same-issues: 0 + exclude-dirs: + - local_dev_data + - vendor diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -136,14 +136,31 @@ @echo "$(GREEN)✓ Test database stopped$(RESET)" ##@ Code Quality -lint: ## Run golangci-lint on the codebase +fmt: ## Format all Go code with gofmt + @echo "$(GREEN)Formatting Go code...$(RESET)" + @gofmt -w ./cmd ./internal ./tests + @echo "$(GREEN)✓ Formatting complete$(RESET)" + +fmt-check: ## Check if Go code is properly formatted + @echo "$(GREEN)Checking code formatting...$(RESET)" + @unformatted=$$(gofmt -l ./cmd ./internal ./tests); \ + if [ -n "$$unformatted" ]; then \ + echo "$(RED)✗ The following files are not formatted:$(RESET)"; \ + echo "$$unformatted"; \ + echo "$(YELLOW)Run 'make fmt' to fix$(RESET)"; \ + exit 1; \ + fi + @echo "$(GREEN)✓ All files are properly formatted$(RESET)" + +lint: fmt-check ## Run golangci-lint on the codebase (includes format check) @echo "$(GREEN)Running linter...$(RESET)" - @golangci-lint run + @golangci-lint run ./cmd/... ./internal/... ./tests/... @echo "$(GREEN)✓ Linting complete$(RESET)" lint-fix: ## Run golangci-lint and auto-fix issues @echo "$(GREEN)Running linter with auto-fix...$(RESET)" - @golangci-lint run --fix + @golangci-lint run --fix ./cmd/... ./internal/... ./tests/... + @gofmt -w ./cmd ./internal ./tests @echo "$(GREEN)✓ Linting complete$(RESET)" ##@ Build & Run