Skip to content

Fix lint failures from golangci-lint v2.12.1 upgrade#768

Merged
rdimitrov merged 1 commit intomainfrom
rdimitrov/fix-golangci-lint-v2.12.1
May 5, 2026
Merged

Fix lint failures from golangci-lint v2.12.1 upgrade#768
rdimitrov merged 1 commit intomainfrom
rdimitrov/fix-golangci-lint-v2.12.1

Conversation

@rdimitrov
Copy link
Copy Markdown
Member

Summary

  • golangci-lint v2.12.1 tightened goconst and added a govet inline check, making CI red on every open PR (Update github actions #766, Update go modules #767, future renovates) even though no code changed
  • Excludes goconst from _test.go and test-fixture files (in line with the existing lll/gocyclo/errcheck/dupl/gosec test exclusions) — table-driven fixtures read better inline than hoisted
  • Fixes the production-code findings properly with named constants (audit target field keys, kubernetes registry/transport types via upstream model.*, telemetry DefaultServiceVersion, etc.) and replaces reflect.Ptr with reflect.Pointer in marshalJSONOrNil for the new govet rule

Why this exists separately

This is purely a CI unblocker — none of the underlying code is broken, only the linter shifted under us. Keeping it as its own PR so #766, #767 and the next batch of renovate PRs can rebase onto a green main without absorbing this churn.

Test plan

  • golangci-lint run --timeout=5m0 issues
  • go build ./... — clean
  • go test -short ./internal/audit/... ./internal/config/... ./internal/kubernetes/... ./internal/telemetry/... — green
  • CI: Linting / Lint Go Code passes
  • CI: full test matrix passes (the renamed audit map keys and kubernetes constants are exercised by the existing test suites)

🤖 Generated with Claude Code

The `golangci-lint` v2.12.1 release tightened `goconst` (now flags
short repeated literals across packages) and added a `govet` `inline`
check, leaving CI red on every open PR. None of the offending code
changed — only the linter did.

Test files account for almost all the new `goconst` noise (table-driven
fixtures with repeated values that read better inline than hoisted into
constants). Add `goconst` to the existing `_test.go` exclusion in
`.golangci.yml`, alongside the `lll`/`gocyclo`/`errcheck`/`dupl`/`gosec`
exclusions already there for the same reason, and extend the rule to
the two test-fixture files (`test_helpers.go`, `testutils_*.go`) that
hold the same kind of repeated data without the `_test.go` suffix.

Production-code findings are fixed properly:

- `internal/audit/{audit,context,middleware}.go`: extract
  `targetField*` constants for the audit target map keys
  (`method`, `path`, `resource_type`, …) and use them everywhere the
  target map is built.
- `internal/config/config.go`: fold the loopback host check into a
  small `isLoopbackHost` helper.
- `internal/kubernetes/types.go`: prefer upstream
  `model.RegistryTypeOCI`, `model.TransportTypeStdio`,
  `model.TransportTypeStreamableHTTP`, and `model.CurrentSchemaURL`
  over hard-coded literals; add local
  `defaultServerVersion`/`defaultServerStatus`/`defaultImageVersion`
  for the remaining defaults.
- `internal/kubernetes/controller.go`: name the literal opt-in
  annotation value as `annotationValueTrue`.
- `internal/sync/writer/db.go`: extract `colServerID` for the FK
  column shared by every per-server `COPY` list, plus
  `skillRegistryTypeOCI`/`skillRegistryTypeGit` for the registry-type
  switch. Also fix the new `govet` finding by replacing
  `reflect.Ptr` (alias) with `reflect.Pointer` (the inlined constant)
  in `marshalJSONOrNil`.
- `internal/telemetry/{config,meter,tracer}.go`: add
  `DefaultServiceVersion = "unknown"` and use it consistently.

`golangci-lint run --timeout=5m` is clean (0 issues). `go build ./...`
and `go test -short` on the touched packages pass.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 49.15254% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.48%. Comparing base (a6da15e) to head (e0ff31f).

Files with missing lines Patch % Lines
internal/audit/context.go 0.00% 27 Missing ⚠️
internal/config/config.go 71.42% 2 Missing ⚠️
internal/kubernetes/types.go 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #768      +/-   ##
==========================================
- Coverage   60.48%   60.48%   -0.01%     
==========================================
  Files         108      108              
  Lines       10576    10580       +4     
==========================================
+ Hits         6397     6399       +2     
- Misses       3609     3611       +2     
  Partials      570      570              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rdimitrov rdimitrov enabled auto-merge (squash) May 5, 2026 09:25
@rdimitrov rdimitrov merged commit 3ce94c2 into main May 5, 2026
14 checks passed
@rdimitrov rdimitrov deleted the rdimitrov/fix-golangci-lint-v2.12.1 branch May 5, 2026 09:31
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.

3 participants