Skip to content

feat: enable modernize linter in golangci-lint and fix all violations#9798

Open
mmorel-35 wants to merge 1 commit into
velero-io:mainfrom
mmorel-35:modernize
Open

feat: enable modernize linter in golangci-lint and fix all violations#9798
mmorel-35 wants to merge 1 commit into
velero-io:mainfrom
mmorel-35:modernize

Conversation

@mmorel-35

@mmorel-35 mmorel-35 commented May 18, 2026

Copy link
Copy Markdown
Contributor

Please add a summary of your change

Enables the modernize linter in the golangci-lint configuration and fixes all reported violations across the codebase. The modernize linter is part of golangci-lint since v2.1.0 and the project already uses v2.12.0, so no tooling version bump is needed.

Changes to .golangci.yaml

  • Added modernize to the linters.enable list
  • Disabled the newexpr check via linters.settings.modernize.disable (placed in alphabetical order within linters.settings) — the golangci-lint auto-fix for newexpr generates syntactically invalid Go code (new(literal_value)new only accepts types, not values), making it unsafe to enable

Fixes applied across 49 Go files

Check Description Files touched
mapsloop Replace for k, v := range src { dst[k] = v } with maps.Copy 10 files
slicescontains Replace manual contains loops with slices.Contains 6 files
stringsseq Replace for _, s := range strings.Split(...) with strings.SplitSeq 7 files
stringscut Replace strings.Index patterns with strings.Cut 3 files
rangeint Replace for i := 0; i < n; i++ {} with for range n {} 8 files
fmtappendf Replace []byte(fmt.Sprintf...) with fmt.Appendf(nil, ...) 2 files
plusbuild Remove legacy // +build lines (replaced by //go:build) 3 files
minmax Replace if/else patterns with max()/min() builtins 1 file
omitzero Replace omitempty (no-op for struct fields) with omitzero 2 files
slicesbackward Replace backward loops with slices.Backward 2 files
waitgroupgo Replace wg.Add(1); go func() { defer wg.Done() ... }() with wg.Go(...) 1 file
atomictypes Replace var x int32 + atomic.*Int32 calls with atomic.Int32 1 file

Please indicate you've done the following:

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
@mmorel-35

Copy link
Copy Markdown
Contributor Author

/kind changelog-not-required

@github-actions github-actions Bot added the kind/changelog-not-required PR does not require a user changelog. Often for docs, website, or build changes label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

has-e2e-2tests has-unit-tests kind/changelog-not-required PR does not require a user changelog. Often for docs, website, or build changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant