Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Updates golangci-lint #635

Merged
merged 2 commits into from
Jun 15, 2023
Merged

Conversation

m1kola
Copy link
Member

@m1kola m1kola commented Jun 14, 2023

Starting version v1.51.0 golangci-lint comes with a new ginkgolinter linter which checks for common ginkgo issues like wrong error assertions (Expect(err).To(BeNil()) instead of Expect(err).NotTo(HaveOccurred())), etc.

This PR does not add ginkgolinter: it will be a followup PR because it will further increase the diff.

In this PR:

  • golangci-lint gets updated from v1.49.0 to v1.53.2
  • depguard linter removed. We do not have configuration for it and new version of golangci-lint comes with the configuration where only Go standard library is allowed.
  • Changes necessary to satisfy new versions of linters (revive and unparam were complaining)

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 14, 2023
@m1kola m1kola marked this pull request as ready for review June 14, 2023 15:57
@m1kola m1kola requested a review from a team as a code owner June 14, 2023 15:57
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 14, 2023
Copy link
Member Author

@m1kola m1kola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments explaining why linters were complaining.

@@ -61,18 +61,18 @@ func DependentPredicateFuncs() crtpredicate.Funcs {
// necessary. Ignore updates that only change the status and
// resourceVersion.
UpdateFunc: func(e event.UpdateEvent) bool {
old := e.ObjectOld.(*unstructured.Unstructured).DeepCopy()
new := e.ObjectNew.(*unstructured.Unstructured).DeepCopy()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New was shadowing built-in new. Renamed old into oldObj for consistency.

@@ -21,7 +21,7 @@ const (
ProvisionerID = "core-rukpak-io-helm"
)

func HandleBundle(ctx context.Context, fsys fs.FS, bundle *rukpakv1alpha1.Bundle) (fs.FS, error) {
func HandleBundle(_ context.Context, fsys fs.FS, _ *rukpakv1alpha1.Bundle) (fs.FS, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in other places with _ args - we don't use args in functions, but we still need args to statisfy interfaces.

@@ -103,14 +103,13 @@ func SetupWithManager(mgr manager.Manager, opts ...Option) error {
}

controllerName := fmt.Sprintf("controller.bundledeployment.%s", c.provisionerID)
l := mgr.GetLogger().WithName(controllerName)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused

}

func (c *controller) reconcile(ctx context.Context, bundle *rukpakv1alpha1.Bundle) (ctrl.Result, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in internal/controllers/bundledeployment/bundledeployment.go we always return an empty value in ctrl.Result{}. It makes sense in Reconcile to satisfy the interface, but not in this unexported func.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree with this change. If we ever do want to return something other than ctrl.Result{}, it'll likely be coming from reconcile(), not Reconcile().

I'd be slightly worried that our future selves would be less inclined to change the return values back to (ctrl.Result, error) and would instead do something less desirable overall.

The primary purpose of this split is to make us not really have to think at all about status updating. The result is merely passed through.

Is a linter complaining about this? If so, WDYT about applying the //nolint:<whatever> label with an explanation along these lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelanford I also was not super happy about this linting issue at first, but ended up obeying because I convinced myself that the code is not set in stone. It is super easy to add a new return param once we have a need for it (especially since this is not an exported method).

To me it is the same as adding input arguments into a function: we usually add new args as the need for them arises. There are exceptions (e.g. designing a public interfaces where signature changes are more painful), but it is not the case here.

But I can look into either adding nolint or disabling this linting rule altogether tomorrow. I am not a big fan of inline linting exceptions, but also do not have very strong objections against them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated: added //nolint:unparam to both

Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 15, 2023
@m1kola m1kola merged commit 1baacc6 into operator-framework:main Jun 15, 2023
@m1kola m1kola deleted the upgrade_golangci branch June 15, 2023 14:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants