fix: enable and fix modernize linter (#26352)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL
2026-02-10 14:02:55 +01:00
committed by GitHub
parent 66835b6ec7
commit 2c5f7317a5
8 changed files with 15 additions and 23 deletions

View File

@@ -22,6 +22,7 @@ linters:
- govet
- importas
- misspell
- modernize
- noctx
- perfsprint
- revive
@@ -121,6 +122,11 @@ linters:
- pkg: github.com/argoproj/argo-cd/v3/util/io
alias: utilio
modernize:
disable:
# Suggest replacing omitempty with omitzero for struct fields.
- omitzero
nolintlint:
require-specific: true

View File

@@ -3,6 +3,7 @@ package managedfields
import (
"bytes"
"fmt"
"slices"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -39,7 +40,7 @@ func Normalize(live, config *unstructured.Unstructured, trustedManagers []string
}
for _, mf := range live.GetManagedFields() {
if trustedManager(mf.Manager, trustedManagers) {
if slices.Contains(trustedManagers, mf.Manager) {
err := normalize(mf, results)
if err != nil {
return nil, nil, fmt.Errorf("error normalizing manager %s: %w", mf.Manager, err)
@@ -114,14 +115,3 @@ func newTypedResults(live, config *unstructured.Unstructured, pt *typed.Parseabl
comparison: comparison,
}, nil
}
// trustedManager will return true if trustedManagers contains curManager.
// Returns false otherwise.
func trustedManager(curManager string, trustedManagers []string) bool {
for _, m := range trustedManagers {
if m == curManager {
return true
}
}
return false
}

View File

@@ -717,7 +717,7 @@ func TestClusterRaceConditionClusterSecrets(t *testing.T) {
}()
// yes, we will take 15 seconds to run this test
// but it reliably triggered the race condition
for i := 0; i < 30; i++ {
for range 30 {
// create a copy so we don't act on the same argo cluster
clusterCopy := cluster.DeepCopy()
_, _ = db.UpdateCluster(ctx, clusterCopy)

View File

@@ -79,7 +79,7 @@ func TestRun_ConcurrentPanicsLogged(t *testing.T) {
const n = 10
var wg sync.WaitGroup
wg.Add(n)
for i := 0; i < n; i++ {
for i := range n {
go func(i int) {
defer wg.Done()
RecoverAndLog(func() { panic(fmt.Sprintf("boom-%d", i)) }, r, "msg")

View File

@@ -277,7 +277,7 @@ func (creds AzureWorkloadIdentityCreds) challengeAzureContainerRegistry(ctx cont
tokenParams := make(map[string]string)
for _, token := range strings.Split(tokens[1], ",") {
for token := range strings.SplitSeq(tokens[1], ",") {
kvPair := strings.Split(token, "=")
tokenParams[kvPair[0]] = strings.Trim(kvPair[1], "\"")
}

View File

@@ -58,10 +58,7 @@ func splitCookie(key, value, attributes string) []string {
var end int
for i, j := 0, 0; i < valueLength; i, j = i+maxValueLength, j+1 {
end = i + maxValueLength
if end > valueLength {
end = valueLength
}
end = min(i+maxValueLength, valueLength)
var cookie string
switch {

View File

@@ -2,6 +2,7 @@ package kube
import (
"context"
"maps"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
@@ -84,9 +85,7 @@ func (ku *kubeUtil) CreateOrUpdateSecretData(ns string, name string, data map[st
if !merge || new {
s.Data = data
} else {
for key, val := range data {
s.Data[key] = val
}
maps.Copy(s.Data, data)
}
return nil
})

View File

@@ -87,7 +87,7 @@ func getTLSCipherSuitesByString(cipherSuites string) ([]uint16, error) {
suiteMap[s.Name] = s.ID
}
allowedSuites := make([]uint16, 0)
for _, s := range strings.Split(cipherSuites, ":") {
for s := range strings.SplitSeq(cipherSuites, ":") {
id, ok := suiteMap[strings.TrimSpace(s)]
if !ok {
return nil, fmt.Errorf("invalid cipher suite specified: %s", s)