Skip to content

Commit

Permalink
fix(lint): explicitly configures ireturn exceptions (opendatahub-io#1085
Browse files Browse the repository at this point in the history
)

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.

(cherry picked from commit 613d552)
  • Loading branch information
bartoszmajsak authored and VaishnaviHire committed Jul 24, 2024
1 parent 718306c commit e3b357f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion controllers/status/reporter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:ireturn //reason: return T which is expected to be satisfying client.Object interface
package status

import (
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugins/addLabelsplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugins/namespacePlugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e3b357f

Please sign in to comment.