Skip to content

Commit

Permalink
lint: enable revive if-return check and fix findings
Browse files Browse the repository at this point in the history
  • Loading branch information
oscr committed Dec 3, 2022
1 parent 8799883 commit 05d935f
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 47 deletions.
6 changes: 5 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,6 +268,10 @@ issues:
- staticcheck
text: "SA1019: in.(.+) is deprecated"
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- revive
text: "if-return: redundant if ...; err != nil check, just return error instead"
path: .*(api|types|test)\/.*\/conversion.*\.go$
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
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
}

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

0 comments on commit 05d935f

Please sign in to comment.