Skip to content

Commit c604a98

Browse files
committed
fix(lint): explicitly configures ireturn exceptions
Instead of using `//nolint:ireturn` the linter allows a use of `generic` return types (on top of the listed defaults which now have been explicitly set). This approach also eliminates a re-occuring issue where `nolintlint` reports aforementioned directive as not used by defined linter. Related issue: golangci/golangci-lint#3228 On top of that we have `--fix` flag enabled for golangci-lint runner. This results in removal of these comments as `nolintlint` tries to autofix. As a consequence the subsequent run of `make lint` yields errors for previously disabled linters and the cycle continues :) > [!IMPORTANT] > This behaviour has also been observed for other linters. As part of this the declarations of kustomize plugin constructor funcs has been reworkted to return struct pointers instead.
1 parent 155dad0 commit c604a98

File tree

6 files changed

+14
-11
lines changed

6 files changed

+14
-11
lines changed

.golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ linters-settings:
4343
alias: $1$2
4444
- pkg: github.com/openshift/api/(\w+)/(v[\w\d]+)
4545
alias: $1$2
46+
ireturn:
47+
allow:
48+
# defaults https://golangci-lint.run/usage/linters/#ireturn
49+
- anon
50+
- error
51+
- empty
52+
- stdlib
53+
# also allow generics
54+
- generic
4655
revive:
4756
rules:
4857
- name: dot-imports

controllers/status/reporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ func NewStatusReporter[T client.Object](cli client.Client, object T, determine D
3131
}
3232

3333
// ReportCondition updates the status of the object using the determineCondition function.
34-
func (r *Reporter[T]) ReportCondition(ctx context.Context, optionalErr error) (T, error) { //nolint:ireturn //reason: returns T satisfying client.Object interface
34+
func (r *Reporter[T]) ReportCondition(ctx context.Context, optionalErr error) (T, error) {
3535
return UpdateWithRetry[T](ctx, r.client, r.object, r.determineCondition(optionalErr))
3636
}
3737

3838
// SaveStatusFunc is a function that allow to define custom logic of updating status of a concrete resource object.
3939
type SaveStatusFunc[T client.Object] func(saved T)
4040

4141
// UpdateWithRetry updates the status of object using passed function and retries on conflict.
42-
func UpdateWithRetry[T client.Object](ctx context.Context, cli client.Client, original T, update SaveStatusFunc[T]) (T, error) { //nolint:ireturn,lll //reason: returns T satisfying client.Object interface
42+
func UpdateWithRetry[T client.Object](ctx context.Context, cli client.Client, original T, update SaveStatusFunc[T]) (T, error) {
4343
saved, ok := original.DeepCopyObject().(T)
4444
if !ok {
4545
return *new(T), errors.New("failed to deep copy object")

pkg/feature/feature_data.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//nolint:ireturn //reason: returning generic T data type
21
package feature
32

43
import (

pkg/feature/provider/types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//nolint:ireturn //reason: returning generic T any (interface{})
21
package provider
32

43
import (
@@ -47,7 +46,7 @@ func (d DataProviderWithDefault[T]) Get(_ context.Context, _ client.Client) (T,
4746
}
4847

4948
// Value returns actual value stored by the provider.
50-
func (d DataProviderWithDefault[T]) Value() T { //nolint:ireturn //reason: returns generic T
49+
func (d DataProviderWithDefault[T]) Value() T {
5150
return d.value
5251
}
5352

pkg/plugins/addLabelsplugin.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
//nolint:ireturn //reason: false positive, builtins.LabelTransformerPlugin is a struct
21
package plugins
32

43
import (
54
"sigs.k8s.io/kustomize/api/builtins" //nolint:staticcheck //Remove after package update
6-
"sigs.k8s.io/kustomize/api/resmap"
75
"sigs.k8s.io/kustomize/api/types"
86
"sigs.k8s.io/kustomize/kyaml/resid"
97

@@ -17,7 +15,7 @@ import (
1715
// - It adds labels to the "metadata/labels" path for all resource kinds.
1816
// - It adds labels to the "spec/template/metadata/labels" and "spec/selector/matchLabels" paths
1917
// for resources of kind "Deployment".
20-
func CreateAddLabelsPlugin(componentName string) resmap.Transformer { //nolint:ireturn //reason returning struct conflicts due to pointer receiver
18+
func CreateAddLabelsPlugin(componentName string) *builtins.LabelTransformerPlugin {
2119
return &builtins.LabelTransformerPlugin{
2220
Labels: map[string]string{
2321
labels.ODH.Component(componentName): "true",

pkg/plugins/namespacePlugin.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
//nolint:ireturn //reason: false positive, builtins.NamespaceTransformerPlugin is a struct
21
package plugins
32

43
import (
54
"sigs.k8s.io/kustomize/api/builtins" //nolint:staticcheck // Remove after package update
65
"sigs.k8s.io/kustomize/api/filters/namespace"
7-
"sigs.k8s.io/kustomize/api/resmap"
86
"sigs.k8s.io/kustomize/api/types"
97
"sigs.k8s.io/kustomize/kyaml/resid"
108
)
119

1210
// CreateNamespaceApplierPlugin creates a plugin to ensure resources have the specified target namespace.
13-
func CreateNamespaceApplierPlugin(targetNamespace string) resmap.Transformer { //nolint:ireturn //reason returning struct conflicts due to pointer receiver
11+
func CreateNamespaceApplierPlugin(targetNamespace string) *builtins.NamespaceTransformerPlugin {
1412
return &builtins.NamespaceTransformerPlugin{
1513
ObjectMeta: types.ObjectMeta{
1614
Name: "odh-namespace-plugin",

0 commit comments

Comments
 (0)