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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ linters-settings:
- name: error-strings
- name: error-naming
- name: exported
#- name: if-return # TODO This is a recommended rule with many findings which may require it's own pr.
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
Expand Down Expand Up @@ -268,17 +268,29 @@ issues:
- staticcheck
text: "SA1019: in.(.+) is deprecated"
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- revive
# Checking if an error is nil to just after return the error or nil is redundant
text: "if-return: redundant if ...; err != nil check, just return error instead"
# Ignoring stylistic checks for generated code
path: .*(api|types|test)\/.*\/conversion.*\.go$
- linters:
- revive
# Exported function and methods should have comments. This warns on undocumented exported functions and methods.
text: exported (method|function|type|const) (.+) should have comment or be unexported
# Ignoring stylistic checks for generated code
path: .*(api|types|test)\/.*\/conversion.*\.go$
- linters:
- revive
# This rule warns when initialism, variable or package naming conventions are not followed.
text: "var-naming: don't use underscores in Go names;"
# Ignoring stylistic checks for generated code
path: .*(api|types|test)\/.*\/conversion.*\.go$
- linters:
- revive
# By convention, receiver names in a method should reflect their identity.
text: "receiver-naming: receiver name"
# Ignoring stylistic checks for generated code
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- stylecheck
Expand Down
6 changes: 1 addition & 5 deletions cmd/clusterctl/client/cluster/cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

}

return nil
return newCRDMigrator(c).Run(ctx, objs)
}

func (cm *certManagerClient) deleteObjs(objs []unstructured.Unstructured) error {
Expand Down
7 changes: 2 additions & 5 deletions cmd/clusterctl/client/cluster/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,10 @@ func (k *proxy) CheckClusterAvailable() error {
}

connectBackoff := newShortConnectBackoff()
if err := retryWithExponentialBackoff(connectBackoff, func() error {
return retryWithExponentialBackoff(connectBackoff, func() error {
_, err := client.New(config, client.Options{Scheme: localScheme})
return err
}); err != nil {
return err
}
return nil
})
}

// ListResources lists namespaced and cluster-wide resources for a component matching the labels. Namespaced resources are only listed
Expand Down
8 changes: 2 additions & 6 deletions hack/tools/mdbook/tabulate/tabulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,9 @@ func (l Tabulate) Process(input *plugin.Input) error {
return err
}

if err := plugin.EachCommand(&input.Book, "/tabs", func(chapter *plugin.BookChapter, args string) (string, error) {
return plugin.EachCommand(&input.Book, "/tabs", func(chapter *plugin.BookChapter, args string) (string, error) {
return "</div></div>", nil
}); err != nil {
return err
}

return nil
})
}

func main() {
Expand Down
16 changes: 4 additions & 12 deletions internal/controllers/clusterclass/clusterclass_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,9 @@ func assertInfrastructureClusterTemplate(ctx context.Context, actualClusterClass
}

// Assert the ClusterClass has the expected APIVersion and Kind of to the infrastructure cluster template
if err := referenceExistsWithCorrectKindAndAPIVersion(actualClusterClass.Spec.Infrastructure.Ref,
return referenceExistsWithCorrectKindAndAPIVersion(actualClusterClass.Spec.Infrastructure.Ref,
builder.GenericInfrastructureClusterTemplateKind,
builder.InfrastructureGroupVersion); err != nil {
return err
}

return nil
builder.InfrastructureGroupVersion)
}

func assertControlPlaneTemplate(ctx context.Context, actualClusterClass *clusterv1.ClusterClass, ns *corev1.Namespace) error {
Expand Down Expand Up @@ -224,13 +220,9 @@ func assertMachineDeploymentClass(ctx context.Context, actualClusterClass *clust
}

// Assert the MachineDeploymentClass has the expected APIVersion and Kind to the bootstrap template
if err := referenceExistsWithCorrectKindAndAPIVersion(mdClass.Template.Bootstrap.Ref,
return referenceExistsWithCorrectKindAndAPIVersion(mdClass.Template.Bootstrap.Ref,
builder.GenericBootstrapConfigTemplateKind,
builder.BootstrapGroupVersion); err != nil {
return err
}

return nil
builder.BootstrapGroupVersion)
}

func assertHasOwnerReference(obj client.Object, ownerRef metav1.OwnerReference) error {
Expand Down
12 changes: 3 additions & 9 deletions internal/controllers/topology/cluster/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,12 +837,9 @@ func assertClusterReconcile(cluster *clusterv1.Cluster) error {
}

// Check if ControlPlaneRef exists is of the expected Kind and APIVersion.
if err := referenceExistsWithCorrectKindAndAPIVersion(cluster.Spec.ControlPlaneRef,
return referenceExistsWithCorrectKindAndAPIVersion(cluster.Spec.ControlPlaneRef,
builder.TestControlPlaneKind,
builder.ControlPlaneGroupVersion); err != nil {
return err
}
return nil
builder.ControlPlaneGroupVersion)
}

// assertInfrastructureClusterReconcile checks if the infrastructureCluster object:
Expand Down Expand Up @@ -1023,10 +1020,7 @@ func assertLabelsAndAnnotations(got client.Object, clusterName string) error {
if err := assertClusterNameLabel(got, clusterName); err != nil {
return err
}
if err := assertTemplateClonedFromNameAnnotation(got); err != nil {
return err
}
return nil
return assertTemplateClonedFromNameAnnotation(got)
}

// assertClusterTopologyOwnedLabel asserts the label exists.
Expand Down
6 changes: 1 addition & 5 deletions internal/controllers/topology/cluster/reconcile_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,7 @@ func (r *Reconciler) callAfterHooks(ctx context.Context, s *scope.Scope) error {
return err
}

if err := r.callAfterClusterUpgrade(ctx, s); err != nil {
return err
}

return nil
return r.callAfterClusterUpgrade(ctx, s)
}

func (r *Reconciler) callAfterControlPlaneInitialized(ctx context.Context, s *scope.Scope) error {
Expand Down
5 changes: 1 addition & 4 deletions internal/runtime/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ type client struct {
}

func (c *client) WarmUp(extensionConfigList *runtimev1.ExtensionConfigList) error {
if err := c.registry.WarmUp(extensionConfigList); err != nil {
return err
}
return nil
return c.registry.WarmUp(extensionConfigList)
}

func (c *client) IsReady() bool {
Expand Down