Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 lint: enable revive if-return check and fix findings #7682

Merged
merged 1 commit into from
Dec 8, 2022

Conversation

oscr
Copy link
Contributor

@oscr oscr commented Dec 3, 2022

What this PR does / why we need it:

Enables the revive if-return check and fixes the findings.

internal/controllers/clusterclass/clusterclass_controller_test.go:128:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
	if err := referenceExistsWithCorrectKindAndAPIVersion(actualClusterClass.Spec.Infrastructure.Ref,
		builder.GenericInfrastructureClusterTemplateKind,
		builder.InfrastructureGroupVersion); err != nil {
		return err
	}
internal/controllers/clusterclass/clusterclass_controller_test.go:227:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
	if err := referenceExistsWithCorrectKindAndAPIVersion(mdClass.Template.Bootstrap.Ref,
		builder.GenericBootstrapConfigTemplateKind,
		builder.BootstrapGroupVersion); err != nil {
		return err
	}
internal/runtime/client/client.go:111:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
	if err := c.registry.WarmUp(extensionConfigList); err != nil {
		return err
	}
internal/controllers/topology/cluster/reconcile_state.go:193:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
	if err := r.callAfterClusterUpgrade(ctx, s); err != nil {
		return err
	}
internal/controllers/topology/cluster/cluster_controller_test.go:840:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
	if err := referenceExistsWithCorrectKindAndAPIVersion(cluster.Spec.ControlPlaneRef,
		builder.TestControlPlaneKind,
		builder.ControlPlaneGroupVersion); err != nil {
		return err
	}
internal/controllers/topology/cluster/cluster_controller_test.go:1026:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
	if err := assertTemplateClonedFromNameAnnotation(got); err != nil {
		return err
	}
cmd/clusterctl/client/cluster/cert_manager.go:292:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
	if err := newCRDMigrator(c).Run(ctx, objs); err != nil {
		return err
	}
cmd/clusterctl/client/cluster/proxy.go:193:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
	if err := retryWithExponentialBackoff(connectBackoff, func() error {
		_, err := client.New(config, client.Options{Scheme: localScheme})
		return err
	}); err != nil {
		return err
	}


hack/tools/mdbook/tabulate/tabulate.go:78:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
        if err := plugin.EachCommand(&input.Book, "/tabs", func(chapter *plugin.BookChapter, args string) (string, error) {
                return "</div></div>", nil
        }); err != nil {
                return err
        }

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #7449

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 3, 2022
@oscr
Copy link
Contributor Author

oscr commented Dec 3, 2022

/test pull-cluster-api-test-main

.golangci.yml Outdated
Comment on lines 273 to 276
text: "if-return: redundant if ...; err != nil check, just return error instead"
path: .*(api|types|test)\/.*\/conversion.*\.go$
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we add a comment explaining why we need these lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean for each specific case? It's in the "Disable linters for conversion" section starting on L266

Copy link
Member

@fabriziopandini fabriziopandini Dec 5, 2022

Choose a reason for hiding this comment

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

just a comment for L273 (text) and one for L274 (path) should be enough
the first one is a little bit opaque, why is this necessary?
the second instead seems kind of intuitive (skip the check for ... even if I'm not sure why are we ignoring api|types|test

@@ -289,11 +289,7 @@ func (cm *certManagerClient) migrateCRDs() error {
return err
}

if err := newCRDMigrator(c).Run(ctx, objs); err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

if someone wanted to wrap the error and add more context to it, will the linter complain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that would be fine. I just removed the err assignment since it wasn't needed as the implementation is right now.

@oscr oscr force-pushed the lint-revive-if-return branch from 05d935f to de575ca Compare December 6, 2022 21:49
@oscr
Copy link
Contributor Author

oscr commented Dec 6, 2022

/test pull-cluster-api-test-mink8s-main

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

Good job on also adding comments in golanci-lint!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 8, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 8, 2022
@k8s-ci-robot k8s-ci-robot merged commit 881c609 into kubernetes-sigs:main Dec 8, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.4 milestone Dec 8, 2022
@oscr oscr deleted the lint-revive-if-return branch December 8, 2022 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable revive check if-return
5 participants