Skip to content

Commit 613d552

Browse files
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: 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. 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.
1 parent 69a7514 commit 613d552

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

.golangci.yml

+9
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

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//nolint:ireturn //reason: return T which is expected to be satisfying client.Object interface
21
package status
32

43
import (

pkg/plugins/addLabelsplugin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
// - It adds labels to the "metadata/labels" path for all resource kinds.
1616
// - It adds labels to the "spec/template/metadata/labels" and "spec/selector/matchLabels" paths
1717
// for resources of kind "Deployment".
18-
func CreateAddLabelsPlugin(componentName string) builtins.LabelTransformerPlugin {
19-
return builtins.LabelTransformerPlugin{
18+
func CreateAddLabelsPlugin(componentName string) *builtins.LabelTransformerPlugin {
19+
return &builtins.LabelTransformerPlugin{
2020
Labels: map[string]string{
2121
labels.ODH.Component(componentName): "true",
2222
labels.K8SCommon.PartOf: componentName,

pkg/plugins/namespacePlugin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
)
99

1010
// CreateNamespaceApplierPlugin creates a plugin to ensure resources have the specified target namespace.
11-
func CreateNamespaceApplierPlugin(targetNamespace string) builtins.NamespaceTransformerPlugin {
12-
return builtins.NamespaceTransformerPlugin{
11+
func CreateNamespaceApplierPlugin(targetNamespace string) *builtins.NamespaceTransformerPlugin {
12+
return &builtins.NamespaceTransformerPlugin{
1313
ObjectMeta: types.ObjectMeta{
1414
Name: "odh-namespace-plugin",
1515
Namespace: targetNamespace,

0 commit comments

Comments
 (0)