Skip to content

Commit 881c609

Browse files
authored
Merge pull request #7682 from oscr/lint-revive-if-return
🌱 lint: enable revive if-return check and fix findings
2 parents 4ee2872 + de575ca commit 881c609

File tree

8 files changed

+27
-47
lines changed

8 files changed

+27
-47
lines changed

.golangci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ linters-settings:
165165
- name: error-strings
166166
- name: error-naming
167167
- name: exported
168-
#- name: if-return # TODO This is a recommended rule with many findings which may require it's own pr.
168+
- name: if-return
169169
- name: increment-decrement
170170
- name: var-naming
171171
- name: var-declaration
@@ -268,17 +268,29 @@ issues:
268268
- staticcheck
269269
text: "SA1019: in.(.+) is deprecated"
270270
path: .*(api|types)\/.*\/conversion.*\.go$
271+
- linters:
272+
- revive
273+
# Checking if an error is nil to just after return the error or nil is redundant
274+
text: "if-return: redundant if ...; err != nil check, just return error instead"
275+
# Ignoring stylistic checks for generated code
276+
path: .*(api|types|test)\/.*\/conversion.*\.go$
271277
- linters:
272278
- revive
279+
# Exported function and methods should have comments. This warns on undocumented exported functions and methods.
273280
text: exported (method|function|type|const) (.+) should have comment or be unexported
281+
# Ignoring stylistic checks for generated code
274282
path: .*(api|types|test)\/.*\/conversion.*\.go$
275283
- linters:
276284
- revive
285+
# This rule warns when initialism, variable or package naming conventions are not followed.
277286
text: "var-naming: don't use underscores in Go names;"
287+
# Ignoring stylistic checks for generated code
278288
path: .*(api|types|test)\/.*\/conversion.*\.go$
279289
- linters:
280290
- revive
291+
# By convention, receiver names in a method should reflect their identity.
281292
text: "receiver-naming: receiver name"
293+
# Ignoring stylistic checks for generated code
282294
path: .*(api|types)\/.*\/conversion.*\.go$
283295
- linters:
284296
- stylecheck

cmd/clusterctl/client/cluster/cert_manager.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,7 @@ func (cm *certManagerClient) migrateCRDs() error {
289289
return err
290290
}
291291

292-
if err := newCRDMigrator(c).Run(ctx, objs); err != nil {
293-
return err
294-
}
295-
296-
return nil
292+
return newCRDMigrator(c).Run(ctx, objs)
297293
}
298294

299295
func (cm *certManagerClient) deleteObjs(objs []unstructured.Unstructured) error {

cmd/clusterctl/client/cluster/proxy.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,10 @@ func (k *proxy) CheckClusterAvailable() error {
190190
}
191191

192192
connectBackoff := newShortConnectBackoff()
193-
if err := retryWithExponentialBackoff(connectBackoff, func() error {
193+
return retryWithExponentialBackoff(connectBackoff, func() error {
194194
_, err := client.New(config, client.Options{Scheme: localScheme})
195195
return err
196-
}); err != nil {
197-
return err
198-
}
199-
return nil
196+
})
200197
}
201198

202199
// ListResources lists namespaced and cluster-wide resources for a component matching the labels. Namespaced resources are only listed

hack/tools/mdbook/tabulate/tabulate.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,9 @@ func (l Tabulate) Process(input *plugin.Input) error {
7575
return err
7676
}
7777

78-
if err := plugin.EachCommand(&input.Book, "/tabs", func(chapter *plugin.BookChapter, args string) (string, error) {
78+
return plugin.EachCommand(&input.Book, "/tabs", func(chapter *plugin.BookChapter, args string) (string, error) {
7979
return "</div></div>", nil
80-
}); err != nil {
81-
return err
82-
}
83-
84-
return nil
80+
})
8581
}
8682

8783
func main() {

internal/controllers/clusterclass/clusterclass_controller_test.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,9 @@ func assertInfrastructureClusterTemplate(ctx context.Context, actualClusterClass
125125
}
126126

127127
// Assert the ClusterClass has the expected APIVersion and Kind of to the infrastructure cluster template
128-
if err := referenceExistsWithCorrectKindAndAPIVersion(actualClusterClass.Spec.Infrastructure.Ref,
128+
return referenceExistsWithCorrectKindAndAPIVersion(actualClusterClass.Spec.Infrastructure.Ref,
129129
builder.GenericInfrastructureClusterTemplateKind,
130-
builder.InfrastructureGroupVersion); err != nil {
131-
return err
132-
}
133-
134-
return nil
130+
builder.InfrastructureGroupVersion)
135131
}
136132

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

226222
// Assert the MachineDeploymentClass has the expected APIVersion and Kind to the bootstrap template
227-
if err := referenceExistsWithCorrectKindAndAPIVersion(mdClass.Template.Bootstrap.Ref,
223+
return referenceExistsWithCorrectKindAndAPIVersion(mdClass.Template.Bootstrap.Ref,
228224
builder.GenericBootstrapConfigTemplateKind,
229-
builder.BootstrapGroupVersion); err != nil {
230-
return err
231-
}
232-
233-
return nil
225+
builder.BootstrapGroupVersion)
234226
}
235227

236228
func assertHasOwnerReference(obj client.Object, ownerRef metav1.OwnerReference) error {

internal/controllers/topology/cluster/cluster_controller_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -837,12 +837,9 @@ func assertClusterReconcile(cluster *clusterv1.Cluster) error {
837837
}
838838

839839
// Check if ControlPlaneRef exists is of the expected Kind and APIVersion.
840-
if err := referenceExistsWithCorrectKindAndAPIVersion(cluster.Spec.ControlPlaneRef,
840+
return referenceExistsWithCorrectKindAndAPIVersion(cluster.Spec.ControlPlaneRef,
841841
builder.TestControlPlaneKind,
842-
builder.ControlPlaneGroupVersion); err != nil {
843-
return err
844-
}
845-
return nil
842+
builder.ControlPlaneGroupVersion)
846843
}
847844

848845
// assertInfrastructureClusterReconcile checks if the infrastructureCluster object:
@@ -1023,10 +1020,7 @@ func assertLabelsAndAnnotations(got client.Object, clusterName string) error {
10231020
if err := assertClusterNameLabel(got, clusterName); err != nil {
10241021
return err
10251022
}
1026-
if err := assertTemplateClonedFromNameAnnotation(got); err != nil {
1027-
return err
1028-
}
1029-
return nil
1023+
return assertTemplateClonedFromNameAnnotation(got)
10301024
}
10311025

10321026
// assertClusterTopologyOwnedLabel asserts the label exists.

internal/controllers/topology/cluster/reconcile_state.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@ func (r *Reconciler) callAfterHooks(ctx context.Context, s *scope.Scope) error {
190190
return err
191191
}
192192

193-
if err := r.callAfterClusterUpgrade(ctx, s); err != nil {
194-
return err
195-
}
196-
197-
return nil
193+
return r.callAfterClusterUpgrade(ctx, s)
198194
}
199195

200196
func (r *Reconciler) callAfterControlPlaneInitialized(ctx context.Context, s *scope.Scope) error {

internal/runtime/client/client.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ type client struct {
108108
}
109109

110110
func (c *client) WarmUp(extensionConfigList *runtimev1.ExtensionConfigList) error {
111-
if err := c.registry.WarmUp(extensionConfigList); err != nil {
112-
return err
113-
}
114-
return nil
111+
return c.registry.WarmUp(extensionConfigList)
115112
}
116113

117114
func (c *client) IsReady() bool {

0 commit comments

Comments
 (0)