Skip to content

Upgrade golangci-lint to v2 and fix all lint issues#433

Open
klowdo wants to merge 31 commits intomainfrom
feat/golangci-lint-upgrade
Open

Upgrade golangci-lint to v2 and fix all lint issues#433
klowdo wants to merge 31 commits intomainfrom
feat/golangci-lint-upgrade

Conversation

@klowdo
Copy link
Collaborator

@klowdo klowdo commented Mar 3, 2026

Description

Migrate golangci-lint from v1.42.1 to v2.10.0 and fix all lint issues across the codebase. Update Makefile lint target to read the version from .tool-versions.

Affected Components

  • All packages (lint fixes across ~40 files)
  • .golangci.yml (migrated to v2 format)
  • .tool-versions (golangci-lint 2.10.0)
  • Makefile (dynamic lint version)

Related Issues

None

Solution and Design

Config migration: .golangci.yml rewritten for v2 format with explicit linter selection, exclusion presets, and formatters section.

Lint fixes by category:

  • interface{}any (Go 1.18+)
  • fmt.Errorf("static")errors.New("static") (perfsprint)
  • for i := 0; i < n; i++for range n (intrange)
  • Remove unnecessary loop variable copies (copyloopvar)
  • Check unchecked error return values (errcheck)
  • Resolve gocritic and staticcheck issues
  • Remove underscore receiver names (ST1006)
  • Use maps.Copy, reflect.TypeFor (modernize)
  • Use HTTP method constants (usestdlibvars)
  • Use typed context keys (SA1029)
  • Remove unnecessary type conversions (uuid)
  • Remove duplicate imports
  • Add //nolint directives for acceptable false positives (gosec in tests)
  • Remove unused code (skipNonRegisteredEvents)

Makefile: Lint target now reads version from .tool-versions instead of hardcoding it.

Steps to test and verify

  1. golangci-lint run passes with zero issues
  2. make test passes
  3. make lint uses the version from .tool-versions

@klowdo klowdo force-pushed the feat/golangci-lint-upgrade branch from d34ae12 to b2e737d Compare March 3, 2026 15:24
@klowdo klowdo changed the title golangci lint upgrade Upgrade golangci-lint to v2 and fix all lint issues Mar 3, 2026
@klowdo klowdo force-pushed the feat/golangci-lint-upgrade branch from 83cd419 to a16bb19 Compare March 4, 2026 08:47
klowdo added 27 commits March 4, 2026 14:23
Migrate .golangci.yml to the v2 config format required by golangci-lint
2.x. Replace enable-all with default:all, update disable list with
current linter names, and add exclusion presets and formatters.
Mechanical replacement of interface{} with the any type alias
introduced in Go 1.18, followed by gofmt to fix alignment.
Use errors.New for static error strings and string concatenation
instead of fmt.Sprintf for simple joins (perfsprint).
Remove unused struct fields and type definitions flagged by the
unused linter.
UUID is a type alias so explicit conversions are redundant.
Convert traditional C-style for loops to Go 1.22+ integer range syntax.
Fix deprecated API usage (ioutil, rand.Seed), possible nil pointer
dereferences in tests, duplicate imports, and simplify boolean/select
expressions.
Rewrite single-case switches to if statements, convert if-else chains
to switch statements, and fix exported parameter naming.
Handle previously ignored error returns across production and test code.
Go 1.22+ captures loop variables correctly, making the re-assignment
pattern `name, tc := name, tc` unnecessary.
Convert C-style for loops to Go 1.22+ integer range syntax in kafka
eventbus and command_check.
Replace fmt.Errorf with errors.New where no format verbs are used.
Omit unused receiver names instead of using underscore.
Define contextKey type for context.WithValue calls (SA1029) and fix
unused variable assignment in acceptance tests.
Replace reflect.TypeOf with reflect.TypeFor, and map copy loops with
maps.Copy.
Replace string literals with http.MethodGet and http.MethodPost.
Apply De Morgan law simplification, replace weak random generators,
add nolint directives for acceptable gosec false positives, add
ReadHeaderTimeout to http.Server, and remove unnecessary conversion.
Fix leading/trailing newline issues flagged by the whitespace linter.
Bump version in .tool-versions and fix newly detected intrange issue.
Use errors.Is() for sentinel error comparisons and %w for error
wrapping in fmt.Errorf calls.
Remove unused function parameters across event bus, event store,
and outbox implementations.
Pass context through function parameters instead of using struct
fields, and add nolint directives where non-inherited contexts are
intentional (bus lifecycle, mongo sessions, scheduled events).
klowdo added 4 commits March 4, 2026 14:23
Zero issues — free to enable.
Suppress intentional context chaining in UnmarshalContext loop.
Add checked type assertions in kafka eventbus, events aggregatestore,
and mock tests.
Suppress intentional context embedding in error structs, test mocks,
outbox lifecycle context, and event bus lifecycle contexts.
@klowdo klowdo force-pushed the feat/golangci-lint-upgrade branch from 85aeb0a to c45e35d Compare March 4, 2026 13:24
@coveralls
Copy link

Coverage Status

coverage: 52.974% (-0.1%) from 53.091%
when pulling c45e35d on feat/golangci-lint-upgrade
into 0a9fd82 on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants