diff --git a/hack/golangci-hints.yaml b/hack/golangci-hints.yaml index ffc183acc7b..1f890c12dff 100644 --- a/hack/golangci-hints.yaml +++ b/hack/golangci-hints.yaml @@ -227,6 +227,7 @@ linters: - ineffassign - kubeapilinter - logcheck + - modernize - revive - sorted - staticcheck @@ -501,6 +502,47 @@ linters: - pattern: ^gomega\.BeFalse$ pkg: ^github.com/onsi/gomega$ msg: "it does not produce a good failure message - use BeFalseBecause with an explicit printf-style failure message instead, or plain Go: if ... { ginkgo.Fail(...) }" + modernize: + # List of analyzers to disable. + # By default, all analyzers are enabled but in + # Kubernetes we want to be more selective and + # disable those which are not useful for it. + disable: + # Replace interface{} with any. + - any + # Replace for-range over b.N with b.Loop. + - bloop + # Replace []byte(fmt.Sprintf) with fmt.Appendf. + - fmtappendf + # Remove redundant re-declaration of loop variables. + - forvar + # Replace explicit loops over maps with calls to maps package. + - mapsloop + # Replace if/else statements with calls to min or max. + - minmax + # Suggest replacing omitempty with omitzero for struct fields. + - omitzero + # Replace 3-clause for loops with for-range over integers. + - rangeint + # Replace reflect.TypeOf(x) with TypeFor[T](). + - reflecttypefor + # Replace loops with slices.Contains or slices.ContainsFunc. + - slicescontains + # Replace sort.Slice with slices.Sort for basic types. + - slicessort + # Use iterators instead of Len/At-style APIs. + - stditerators + # Replace HasPrefix/TrimPrefix with CutPrefix. + - stringscutprefix + # Replace ranging over Split/Fields with SplitSeq/FieldsSeq. + - stringsseq + # Replace += with strings.Builder. + - stringsbuilder + # Replace context.WithCancel with t.Context in tests. + - testingcontext + # Replace wg.Add(1)/go/wg.Done() with wg.Go. + - waitgroup + revive: # Only these rules are enabled. rules: diff --git a/hack/golangci.yaml b/hack/golangci.yaml index 4fcbf5ba166..b70edd94786 100644 --- a/hack/golangci.yaml +++ b/hack/golangci.yaml @@ -237,6 +237,7 @@ linters: - ineffassign - kubeapilinter - logcheck + - modernize - revive - sorted - staticcheck @@ -522,6 +523,47 @@ linters: - typeSwitchVar - underef - unslice + modernize: + # List of analyzers to disable. + # By default, all analyzers are enabled but in + # Kubernetes we want to be more selective and + # disable those which are not useful for it. + disable: + # Replace interface{} with any. + - any + # Replace for-range over b.N with b.Loop. + - bloop + # Replace []byte(fmt.Sprintf) with fmt.Appendf. + - fmtappendf + # Remove redundant re-declaration of loop variables. + - forvar + # Replace explicit loops over maps with calls to maps package. + - mapsloop + # Replace if/else statements with calls to min or max. + - minmax + # Suggest replacing omitempty with omitzero for struct fields. + - omitzero + # Replace 3-clause for loops with for-range over integers. + - rangeint + # Replace reflect.TypeOf(x) with TypeFor[T](). + - reflecttypefor + # Replace loops with slices.Contains or slices.ContainsFunc. + - slicescontains + # Replace sort.Slice with slices.Sort for basic types. + - slicessort + # Use iterators instead of Len/At-style APIs. + - stditerators + # Replace HasPrefix/TrimPrefix with CutPrefix. + - stringscutprefix + # Replace ranging over Split/Fields with SplitSeq/FieldsSeq. + - stringsseq + # Replace += with strings.Builder. + - stringsbuilder + # Replace context.WithCancel with t.Context in tests. + - testingcontext + # Replace wg.Add(1)/go/wg.Done() with wg.Go. + - waitgroup + revive: # Only these rules are enabled. rules: diff --git a/hack/golangci.yaml.in b/hack/golangci.yaml.in index 9d47657737a..4c73dd2e971 100644 --- a/hack/golangci.yaml.in +++ b/hack/golangci.yaml.in @@ -169,6 +169,7 @@ linters: - ineffassign - kubeapilinter - logcheck + - modernize - revive - sorted - staticcheck @@ -268,6 +269,47 @@ linters: - underef - unslice {{- end}} + modernize: + # List of analyzers to disable. + # By default, all analyzers are enabled but in + # Kubernetes we want to be more selective and + # disable those which are not useful for it. + disable: + # Replace interface{} with any. + - any + # Replace for-range over b.N with b.Loop. + - bloop + # Replace []byte(fmt.Sprintf) with fmt.Appendf. + - fmtappendf + # Remove redundant re-declaration of loop variables. + - forvar + # Replace explicit loops over maps with calls to maps package. + - mapsloop + # Replace if/else statements with calls to min or max. + - minmax + # Suggest replacing omitempty with omitzero for struct fields. + - omitzero + # Replace 3-clause for loops with for-range over integers. + - rangeint + # Replace reflect.TypeOf(x) with TypeFor[T](). + - reflecttypefor + # Replace loops with slices.Contains or slices.ContainsFunc. + - slicescontains + # Replace sort.Slice with slices.Sort for basic types. + - slicessort + # Use iterators instead of Len/At-style APIs. + - stditerators + # Replace HasPrefix/TrimPrefix with CutPrefix. + - stringscutprefix + # Replace ranging over Split/Fields with SplitSeq/FieldsSeq. + - stringsseq + # Replace += with strings.Builder. + - stringsbuilder + # Replace context.WithCancel with t.Context in tests. + - testingcontext + # Replace wg.Add(1)/go/wg.Done() with wg.Go. + - waitgroup + revive: # Only these rules are enabled. rules: