Skip to content

Modernize golangci-lint config and switch formatter to gofumpt#435

Merged
kodiakhq[bot] merged 1 commit into
masterfrom
ci/golangci-lint-gofumpt
Jul 10, 2026
Merged

Modernize golangci-lint config and switch formatter to gofumpt#435
kodiakhq[bot] merged 1 commit into
masterfrom
ci/golangci-lint-gofumpt

Conversation

@tamalsaha

Copy link
Copy Markdown
Contributor

Summary

Modernize the .golangci.yml configuration for golangci-lint v2 and switch the configured formatter to gofumpt (mirrors kmodules/resource-metadata#657).

This aligns the linter with the build image (ghcr.io/appscode/golang-dev:1.25), where gofmt is already a symlink shim to gofumpt v0.7.0 — so make fmt (via hack/fmt.sh's gofmt -s -w) and the linter now enforce the same formatting. No change to hack/fmt.sh is needed.

.golangci.yml

  • Enable bodyclose and prealloc linters (unparam was already enabled).
  • Move exclude-files / exclude-dirs out of the deprecated issues: block into linters.exclusions.paths — the correct location in golangci-lint v2.
  • Fix the over-escaped exclusion regex generated.*\\.gogenerated.*\.go (the double backslash matched a literal backslash rather than a dot).
  • Switch the formatter from gofmtgofumpt and drop the now-unneeded interface{}any rewrite rule (gofumpt performs this itself at go1.18+, and go.mod pins go1.25).

golangci-lint config verify passes and golangci-lint run reports 0 issues.

Code fixes for the newly enabled linters

  • pkg/cmds/server/start.go: preallocate the validation errors slice (prealloc), capturing RecommendedOptions.Validate() once instead of calling it twice.
  • pkg/graph/setup.go: preallocate the errs slice with len(result.Errors) capacity (prealloc).

Resulting formatting

gofumpt reformat of several files (multi-line call-argument wrapping in apis/**/register.go, pkg/apiserver, pkg/graph, pkg/registry/**, and a controller test).

Test plan

  • golangci-lint config verify — valid
  • golangci-lint run — 0 issues
  • go build ./pkg/cmds/server/... ./pkg/graph/...

- Enable bodyclose and prealloc linters
- Move exclude-files/exclude-dirs to linters.exclusions.paths (golangci-lint
  v2 location) and fix over-escaped regex generated.*\\.go -> generated.*\.go
- Switch formatter from gofmt to gofumpt and drop the interface{} -> any
  rewrite rule (gofumpt is a stricter superset)
- Preallocate error slices flagged by prealloc in server start options
  validation and graphql query execution
- Apply resulting gofumpt formatting

Signed-off-by: Tamal Saha <tamal@appscode.com>
@tamalsaha tamalsaha added the automerge Kodiak will auto merge PRs that have this label label Jul 10, 2026
@kodiakhq
kodiakhq Bot merged commit 10ce260 into master Jul 10, 2026
4 checks passed
@kodiakhq
kodiakhq Bot deleted the ci/golangci-lint-gofumpt branch July 10, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Kodiak will auto merge PRs that have this label

Development

Successfully merging this pull request may close these issues.

1 participant