Skip to content

Commit 3dfd579

Browse files
committed
make fix-golangci-lint
Signed-off-by: Erik Godding Boye <[email protected]>
1 parent ae48d6d commit 3dfd579

File tree

12 files changed

+34
-32
lines changed

12 files changed

+34
-32
lines changed

.golangci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ linters:
1111
paths: [third_party, builtin$, examples$]
1212
warn-unused: true
1313
settings:
14+
modernize:
15+
disable:
16+
# TODO(erikgb): Consider if the omitzero linter makes sense in this project
17+
- omitzero
1418
staticcheck:
1519
checks: ["all", "-ST1000", "-ST1001", "-ST1003", "-ST1005", "-ST1012", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-QF1001", "-QF1003", "-QF1008"]
1620
enable:

internal/versionchecker/test/getpodfromtemplate_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package versionchecker
1818

1919
import (
2020
"fmt"
21+
"maps"
2122

2223
v1 "k8s.io/api/core/v1"
2324
"k8s.io/apimachinery/pkg/api/meta"
@@ -63,9 +64,7 @@ func getPodFromTemplate(template *v1.PodTemplateSpec, parentObject runtime.Objec
6364

6465
func getPodsLabelSet(template *v1.PodTemplateSpec) labels.Set {
6566
desiredLabels := make(labels.Set)
66-
for k, v := range template.Labels {
67-
desiredLabels[k] = v
68-
}
67+
maps.Copy(desiredLabels, template.Labels)
6968
return desiredLabels
7069
}
7170

@@ -77,9 +76,7 @@ func getPodsFinalizers(template *v1.PodTemplateSpec) []string {
7776

7877
func getPodsAnnotationSet(template *v1.PodTemplateSpec) labels.Set {
7978
desiredAnnotations := make(labels.Set)
80-
for k, v := range template.Annotations {
81-
desiredAnnotations[k] = v
82-
}
79+
maps.Copy(desiredAnnotations, template.Annotations)
8380
return desiredAnnotations
8481
}
8582

internal/versionchecker/test/testdata/fetch.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ func (inv *Inventory) read(manifestsPath string) error {
203203
// Split the rest of the file into the manifests
204204
manfestsBytes = fileSplit[1]
205205

206-
manifests := bytes.Split(manfestsBytes, []byte("---\n# [CHK_VERSIONS]: "))
206+
manifests := bytes.SplitSeq(manfestsBytes, []byte("---\n# [CHK_VERSIONS]: "))
207207

208-
for _, manifest := range manifests {
208+
for manifest := range manifests {
209209
if len(manifest) == 0 {
210210
continue
211211
}
@@ -232,8 +232,8 @@ func (inv *Inventory) read(manifestsPath string) error {
232232
manifestHash := hex.EncodeToString(manifestHasher.Sum([]byte{}))
233233

234234
// Split the versions
235-
versionsSplit := strings.Split(versions, ",")
236-
for _, version := range versionsSplit {
235+
versionsSplit := strings.SplitSeq(versions, ",")
236+
for version := range versionsSplit {
237237
version = strings.TrimSpace(version)
238238
version = semver.Canonical(version)
239239

@@ -385,7 +385,7 @@ func cleanupManifests(manifests []byte, version string) ([]byte, error) {
385385

386386
decoder := yaml.NewDecoder(bytes.NewBuffer(manifests))
387387
for {
388-
var manifest map[string]interface{}
388+
var manifest map[string]any
389389

390390
err := decoder.Decode(&manifest)
391391
if errors.Is(err, io.EOF) {
@@ -407,10 +407,10 @@ func cleanupManifests(manifests []byte, version string) ([]byte, error) {
407407
case "CustomResourceDefinition":
408408
// remove all CRD schemas from yaml file
409409
switch spec := manifest["spec"].(type) {
410-
case map[string]interface{}:
411-
spec["versions"] = []interface{}{}
412-
case map[interface{}]interface{}:
413-
spec["versions"] = []interface{}{}
410+
case map[string]any:
411+
spec["versions"] = []any{}
412+
case map[any]any:
413+
spec["versions"] = []any{}
414414
}
415415

416416
// remove status from CRD

internal/versionchecker/test/versionchecker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func loadManifests(t *testing.T) []testManifest {
7070
testManifestBytes = split[1]
7171

7272
var manifests []testManifest
73-
for _, manifest := range bytes.Split(testManifestBytes, []byte("---\n# [CHK_VERSIONS]: ")) {
73+
for manifest := range bytes.SplitSeq(testManifestBytes, []byte("---\n# [CHK_VERSIONS]: ")) {
7474
if len(manifest) == 0 {
7575
continue
7676
}

pkg/convert/internal/apis/acme/fuzzer/fuzzer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
)
2727

2828
// Funcs returns the fuzzer functions for the apps api group.
29-
var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
30-
return []interface{}{
29+
var Funcs = func(codecs runtimeserializer.CodecFactory) []any {
30+
return []any{
3131
func(s *acme.Order, c randfill.Continue) {
3232
c.FillNoCustom(s) // fuzz self without calling this function again
3333

pkg/convert/internal/apis/certmanager/fuzzer/fuzzer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727
)
2828

2929
// Funcs returns the fuzzer functions for the apps api group.
30-
var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
31-
return append(acmefuzzer.Funcs(codecs), []interface{}{
30+
var Funcs = func(codecs runtimeserializer.CodecFactory) []any {
31+
return append(acmefuzzer.Funcs(codecs), []any{
3232
func(s *certmanager.Certificate, c randfill.Continue) {
3333
c.FillNoCustom(s) // fuzz self without calling this function again
3434

pkg/convert/internal/apis/meta/fuzzer/fuzzer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ import (
2121
)
2222

2323
// Funcs returns the fuzzer functions for the apps api group.
24-
var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
25-
return []interface{}{}
24+
var Funcs = func(codecs runtimeserializer.CodecFactory) []any {
25+
return []any{}
2626
}

pkg/convert/scheme.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ var Scheme = func() *runtime.Scheme {
4646
utilruntime.Must(metainternalversion.AddToScheme(scheme))
4747

4848
// Adds the conversion between internalmeta.List and corev1.List
49-
_ = scheme.AddConversionFunc((*corev1.List)(nil), (*metainternalversion.List)(nil), func(a, b interface{}, scope conversion.Scope) error {
49+
_ = scheme.AddConversionFunc((*corev1.List)(nil), (*metainternalversion.List)(nil), func(a, b any, scope conversion.Scope) error {
5050
metaList := &metav1.List{}
5151
metaList.Items = a.(*corev1.List).Items
5252
return metainternalversion.Convert_v1_List_To_internalversion_List(metaList, b.(*metainternalversion.List), scope)
5353
})
5454

55-
_ = scheme.AddConversionFunc((*metainternalversion.List)(nil), (*corev1.List)(nil), func(a, b interface{}, scope conversion.Scope) error {
55+
_ = scheme.AddConversionFunc((*metainternalversion.List)(nil), (*corev1.List)(nil), func(a, b any, scope conversion.Scope) error {
5656
metaList := &metav1.List{}
5757
err := metainternalversion.Convert_internalversion_List_To_v1_List(a.(*metainternalversion.List), metaList, scope)
5858
if err != nil {

pkg/install/helm/settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (n *NormalisedEnvSettings) InitActionConfiguration() error {
116116
n.Factory.RESTClientGetter,
117117
n.Factory.Namespace,
118118
os.Getenv("HELM_DRIVER"),
119-
func(format string, v ...interface{}) {
119+
func(format string, v ...any) {
120120
n.logger.Info(fmt.Sprintf(format, v...))
121121
},
122122
)

pkg/status/certificate/certificate.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"strings"
2324
"time"
2425

2526
cmacme "github.com/cert-manager/cert-manager/pkg/apis/acme/v1"
@@ -271,12 +272,12 @@ func StatusFromResources(data *Data) *CertificateStatus {
271272

272273
// formatStringSlice takes in a string slice and formats the contents of the slice
273274
// into a single string where each element of the slice is prefixed with "- " and on a new line
274-
func formatStringSlice(strings []string) string {
275-
result := ""
276-
for _, str := range strings {
277-
result += "- " + str + "\n"
275+
func formatStringSlice(strs []string) string {
276+
var result strings.Builder
277+
for _, str := range strs {
278+
result.WriteString("- " + str + "\n")
278279
}
279-
return result
280+
return result.String()
280281
}
281282

282283
// formatTimeString returns the time as a string

0 commit comments

Comments
 (0)