Skip to content

Commit

Permalink
Improve linting in project
Browse files Browse the repository at this point in the history
- Add golangci-lint fetching in Makefile
- Add ginkgolinter to golangci linting configuration
- Fix existing gomega/ginkgo linting issues
  • Loading branch information
afritzler committed Nov 9, 2023
1 parent 3c6f0b6 commit a8084f6
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.1
version: v1.55.2
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ run:
linters:
enable:
- revive
- ginkgolinter
- ineffassign
- misspell
- goimports
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Image URL to use all building/pushing image targets
CONTROLLER_IMG ?= controller:latest
APISERVER_IMG ?= apiserver:latest
Expand Down Expand Up @@ -112,8 +111,8 @@ vet: ## Run go vet against code.
go vet ./...

.PHONY: lint
lint: ## Run golangci-lint on the code.
golangci-lint run ./...
lint: golangci-lint ## Run golangci-lint on the code.
$(GOLANGCI_LINT) run ./...

.PHONY: clean
clean: ## Clean any artifacts that can be regenerated.
Expand Down Expand Up @@ -369,6 +368,7 @@ ADDLICENSE ?= $(LOCALBIN)/addlicense
PROTOC_GEN_GOGO ?= $(LOCALBIN)/protoc-gen-gogo
MODELS_SCHEMA ?= $(LOCALBIN)/models-schema
GOIMPORTS ?= $(LOCALBIN)/goimports
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint

## Tool Versions
KUSTOMIZE_VERSION ?= v5.1.1
Expand All @@ -379,6 +379,7 @@ GEN_CRD_API_REFERENCE_DOCS_VERSION ?= v0.3.0
ADDLICENSE_VERSION ?= v1.1.1
PROTOC_GEN_GOGO_VERSION ?= v1.3.2
GOIMPORTS_VERSION ?= v0.13.0
GOLANGCI_LINT_VERSION ?= v1.55.2

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand Down Expand Up @@ -480,3 +481,8 @@ $(MODELS_SCHEMA): $(LOCALBIN)
goimports: $(GOIMPORTS) ## Download goimports locally if necessary.
$(GOIMPORTS): $(LOCALBIN)
test -s $(LOCALBIN)/goimports || GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var _ = Describe("Admission", func() {
By("patching the Volume to increase the Volume size")
volumeBase := volume.DeepCopy()
volume.Spec.Resources[corev1alpha1.ResourceStorage] = resource.MustParse("2Gi")
Expect(k8sClient.Patch(ctx, volume, client.MergeFrom(volumeBase)))
Expect(k8sClient.Patch(ctx, volume, client.MergeFrom(volumeBase))).To(Succeed())

By("ensuring that Volume has been resized")
Consistently(Object(volume)).Should(SatisfyAll(
Expand Down
6 changes: 3 additions & 3 deletions internal/app/compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ var _ = Describe("Compute", func() {
Expect(k8sClient.List(ctx, machinesOnMachinePool1List,
client.InNamespace(ns.Name),
client.MatchingFields{computev1alpha1.MachineMachinePoolRefNameField: machinePool1},
))
)).To(Succeed())

By("inspecting the items")
Expect(machinesOnMachinePool1List.Items).To(ConsistOf(*machine1))
Expand All @@ -232,7 +232,7 @@ var _ = Describe("Compute", func() {
Expect(k8sClient.List(ctx, machinesOnMachinePool2List,
client.InNamespace(ns.Name),
client.MatchingFields{computev1alpha1.MachineMachinePoolRefNameField: machinePool2},
))
)).To(Succeed())

By("inspecting the items")
Expect(machinesOnMachinePool2List.Items).To(ConsistOf(*machine2))
Expand All @@ -242,7 +242,7 @@ var _ = Describe("Compute", func() {
Expect(k8sClient.List(ctx, machinesOnNoMachinePoolList,
client.InNamespace(ns.Name),
client.MatchingFields{computev1alpha1.MachineMachinePoolRefNameField: ""},
))
)).To(Succeed())

By("inspecting the items")
Expect(machinesOnNoMachinePoolList.Items).To(ConsistOf(*machine3))
Expand Down
12 changes: 6 additions & 6 deletions internal/app/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var _ = Describe("Storage", func() {
Expect(k8sClient.List(ctx, volumesOnVolumePool1List,
client.InNamespace(ns.Name),
client.MatchingFields{storagev1alpha1.VolumeVolumePoolRefNameField: volumePool1},
))
)).To(Succeed())

By("inspecting the items")
Expect(volumesOnVolumePool1List.Items).To(ConsistOf(*volume1))
Expand All @@ -129,7 +129,7 @@ var _ = Describe("Storage", func() {
Expect(k8sClient.List(ctx, volumesOnVolumePool2List,
client.InNamespace(ns.Name),
client.MatchingFields{storagev1alpha1.VolumeVolumePoolRefNameField: volumePool2},
))
)).To(Succeed())

By("inspecting the items")
Expect(volumesOnVolumePool2List.Items).To(ConsistOf(*volume2))
Expand All @@ -139,7 +139,7 @@ var _ = Describe("Storage", func() {
Expect(k8sClient.List(ctx, volumesOnNoVolumePoolList,
client.InNamespace(ns.Name),
client.MatchingFields{storagev1alpha1.VolumeVolumePoolRefNameField: ""},
))
)).To(Succeed())

By("inspecting the items")
Expect(volumesOnNoVolumePoolList.Items).To(ConsistOf(*volume3))
Expand Down Expand Up @@ -258,7 +258,7 @@ var _ = Describe("Storage", func() {
Expect(k8sClient.List(ctx, bucketsOnBucketPool1List,
client.InNamespace(ns.Name),
client.MatchingFields{storagev1alpha1.BucketBucketPoolRefNameField: bucketPool1},
))
)).To(Succeed())

By("inspecting the items")
Expect(bucketsOnBucketPool1List.Items).To(ConsistOf(*bucket1))
Expand All @@ -268,7 +268,7 @@ var _ = Describe("Storage", func() {
Expect(k8sClient.List(ctx, bucketsOnBucketPool2List,
client.InNamespace(ns.Name),
client.MatchingFields{storagev1alpha1.BucketBucketPoolRefNameField: bucketPool2},
))
)).To(Succeed())

By("inspecting the items")
Expect(bucketsOnBucketPool2List.Items).To(ConsistOf(*bucket2))
Expand All @@ -278,7 +278,7 @@ var _ = Describe("Storage", func() {
Expect(k8sClient.List(ctx, bucketsOnNoBucketPoolList,
client.InNamespace(ns.Name),
client.MatchingFields{storagev1alpha1.BucketBucketPoolRefNameField: ""},
))
)).To(Succeed())

By("inspecting the items")
Expect(bucketsOnNoBucketPoolList.Items).To(ConsistOf(*bucket3))
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/compute/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ var _ = BeforeSuite(func() {

Expect((&MachineEphemeralNetworkInterfaceReconciler{
Client: k8sManager.GetClient(),
}).SetupWithManager(k8sManager))
}).SetupWithManager(k8sManager)).To(Succeed())

Expect((&MachineEphemeralVolumeReconciler{
Client: k8sManager.GetClient(),
}).SetupWithManager(k8sManager))
}).SetupWithManager(k8sManager)).To(Succeed())

Expect((&MachineClassReconciler{
Client: k8sManager.GetClient(),
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/core/core_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var _ = BeforeSuite(func() {
Expect(err).ToNot(HaveOccurred())

registry := quota.NewRegistry(scheme.Scheme)
Expect(quota.AddAllToRegistry(registry, quotaevaluatoronmetal.NewEvaluatorsForControllers(k8sManager.GetClient())))
Expect(quota.AddAllToRegistry(registry, quotaevaluatoronmetal.NewEvaluatorsForControllers(k8sManager.GetClient()))).To(Succeed())

replenishReconcilers, err := quotacontrolleronmetal.NewReplenishReconcilers(k8sManager.GetClient(), registry)
Expect(err).NotTo(HaveOccurred())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var _ = Describe("NetworkProtectionReconciler", func() {
By("ensuring that the network has been deleted")
Eventually(func(g Gomega) {
err := k8sClient.Get(ctx, networkKey, network)
Expect(client.IgnoreNotFound(err)).To(BeNil())
Expect(client.IgnoreNotFound(err)).To(Succeed())
}).Should(Succeed())
})

Expand Down Expand Up @@ -146,7 +146,7 @@ var _ = Describe("NetworkProtectionReconciler", func() {
By("ensuring that the network has been deleted")
Eventually(func(g Gomega) {
err := k8sClient.Get(ctx, networkKey, network)
Expect(client.IgnoreNotFound(err)).To(BeNil())
Expect(client.IgnoreNotFound(err)).To(Succeed())
}).Should(Succeed())
})

Expand Down Expand Up @@ -232,7 +232,7 @@ var _ = Describe("NetworkProtectionReconciler", func() {
}
Eventually(func(g Gomega) {
err := k8sClient.Get(ctx, networkKey, network)
Expect(client.IgnoreNotFound(err)).To(BeNil())
Expect(client.IgnoreNotFound(err)).To(Succeed())
}).Should(Succeed())
})
})
2 changes: 1 addition & 1 deletion utils/context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var _ = Describe("Context", func() {
ctx := FromStopChannel(stopChan)

Expect(ctx.Done()).NotTo(BeClosed())
Expect(ctx.Err()).To(BeNil())
Expect(ctx.Err()).To(Succeed())

close(stopChan)

Expand Down

0 comments on commit a8084f6

Please sign in to comment.