From 613d55246d6f9b858c542d398c69f3b86c03d758 Mon Sep 17 00:00:00 2001 From: Bartosz Majsak Date: Wed, 26 Jun 2024 18:17:56 +0200 Subject: [PATCH] fix(lint): explicitly configures ireturn exceptions (#1085) 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: https://github.com/golangci/golangci-lint/issues/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. The reason for this is that in our feature branch we are relying on kustomize plugins and want to iterate over a slice of resmap.Transfomers but in the current form these functions cannot be used due to the fact that structs returned have pointer receivers. From the current functionality standpoint (on incubation branch) this change is harmless. --- .golangci.yml | 9 +++++++++ controllers/status/reporter.go | 1 - pkg/plugins/addLabelsplugin.go | 4 ++-- pkg/plugins/namespacePlugin.go | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f6305b15132..33d7ac791a0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -43,6 +43,15 @@ linters-settings: alias: $1$2 - pkg: github.com/openshift/api/(\w+)/(v[\w\d]+) alias: $1$2 + ireturn: + allow: + # defaults https://golangci-lint.run/usage/linters/#ireturn + - anon + - error + - empty + - stdlib + # also allow generics + - generic revive: rules: - name: dot-imports diff --git a/controllers/status/reporter.go b/controllers/status/reporter.go index e5b3679ff32..de9dbe7e6fc 100644 --- a/controllers/status/reporter.go +++ b/controllers/status/reporter.go @@ -1,4 +1,3 @@ -//nolint:ireturn //reason: return T which is expected to be satisfying client.Object interface package status import ( diff --git a/pkg/plugins/addLabelsplugin.go b/pkg/plugins/addLabelsplugin.go index 573a19f2ad2..5991c157d4c 100644 --- a/pkg/plugins/addLabelsplugin.go +++ b/pkg/plugins/addLabelsplugin.go @@ -15,8 +15,8 @@ import ( // - It adds labels to the "metadata/labels" path for all resource kinds. // - It adds labels to the "spec/template/metadata/labels" and "spec/selector/matchLabels" paths // for resources of kind "Deployment". -func CreateAddLabelsPlugin(componentName string) builtins.LabelTransformerPlugin { - return builtins.LabelTransformerPlugin{ +func CreateAddLabelsPlugin(componentName string) *builtins.LabelTransformerPlugin { + return &builtins.LabelTransformerPlugin{ Labels: map[string]string{ labels.ODH.Component(componentName): "true", labels.K8SCommon.PartOf: componentName, diff --git a/pkg/plugins/namespacePlugin.go b/pkg/plugins/namespacePlugin.go index 7060b6330c4..5204fdaa892 100644 --- a/pkg/plugins/namespacePlugin.go +++ b/pkg/plugins/namespacePlugin.go @@ -8,8 +8,8 @@ import ( ) // CreateNamespaceApplierPlugin creates a plugin to ensure resources have the specified target namespace. -func CreateNamespaceApplierPlugin(targetNamespace string) builtins.NamespaceTransformerPlugin { - return builtins.NamespaceTransformerPlugin{ +func CreateNamespaceApplierPlugin(targetNamespace string) *builtins.NamespaceTransformerPlugin { + return &builtins.NamespaceTransformerPlugin{ ObjectMeta: types.ObjectMeta{ Name: "odh-namespace-plugin", Namespace: targetNamespace,