-
Notifications
You must be signed in to change notification settings - Fork 1.2k
🏃 Update linter and lint fixes #773
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
linters: | ||
disable-all: true | ||
enable: | ||
- misspell | ||
- structcheck | ||
- golint | ||
- deadcode | ||
- errcheck | ||
- varcheck | ||
- goconst | ||
- unparam | ||
- ineffassign | ||
- nakedret | ||
- interfacer | ||
- gocyclo | ||
- lll | ||
- dupl | ||
- goimports | ||
|
||
linters-settings: | ||
lll: | ||
line-length: 170 | ||
dupl: | ||
threshold: 400 | ||
|
||
run: | ||
timeout: 5m | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 cool |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,30 +24,6 @@ go vet ${MOD_OPT} ./... | |
|
||
header_text "running golangci-lint" | ||
|
||
golangci-lint run --disable-all \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 cool |
||
--deadline 5m \ | ||
--enable=misspell \ | ||
--enable=structcheck \ | ||
--enable=golint \ | ||
--enable=deadcode \ | ||
--enable=errcheck \ | ||
--enable=varcheck \ | ||
--enable=goconst \ | ||
--enable=unparam \ | ||
--enable=ineffassign \ | ||
--enable=nakedret \ | ||
--enable=interfacer \ | ||
--enable=misspell \ | ||
--enable=gocyclo \ | ||
--enable=lll \ | ||
--enable=dupl \ | ||
--enable=goimports \ | ||
--enable=bodyclose \ | ||
./pkg/... ./examples/... . | ||
|
||
# TODO: Enable these as we fix them to make them pass | ||
# --enable=gosec \ | ||
# --enable=maligned \ | ||
# --enable=safesql \ | ||
golangci-lint run ./pkg/... ./examples/... . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following linters have been removed and are NOT enabled by default
Is this intended? If we plan to keep them... it would be great to add them to the https://github.com/golangci/golangci-lint#enabled-by-default-linters There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this was not my intention. I misinterpreted how dropping the |
||
|
||
GO111MODULES=on go list -mod=readonly ./... |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ limitations under the License. | |
package fake | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
. "github.com/onsi/ginkgo" | ||
|
@@ -85,7 +86,7 @@ var _ = Describe("Fake client", func() { | |
Namespace: "ns1", | ||
} | ||
obj := &appsv1.Deployment{} | ||
err := cl.Get(nil, namespacedName, obj) | ||
err := cl.Get(context.Background(), namespacedName, obj) | ||
Expect(err).To(BeNil()) | ||
Expect(obj).To(Equal(dep)) | ||
}) | ||
|
@@ -99,14 +100,14 @@ var _ = Describe("Fake client", func() { | |
obj := &unstructured.Unstructured{} | ||
obj.SetAPIVersion("apps/v1") | ||
obj.SetKind("Deployment") | ||
err := cl.Get(nil, namespacedName, obj) | ||
err := cl.Get(context.Background(), namespacedName, obj) | ||
Expect(err).To(BeNil()) | ||
}) | ||
|
||
It("should be able to List", func() { | ||
By("Listing all deployments in a namespace") | ||
list := &appsv1.DeploymentList{} | ||
err := cl.List(nil, list, client.InNamespace("ns1")) | ||
err := cl.List(context.Background(), list, client.InNamespace("ns1")) | ||
Expect(err).To(BeNil()) | ||
Expect(list.Items).To(HaveLen(2)) | ||
Expect(list.Items).To(ConsistOf(*dep, *dep2)) | ||
|
@@ -117,15 +118,15 @@ var _ = Describe("Fake client", func() { | |
list := &unstructured.UnstructuredList{} | ||
list.SetAPIVersion("apps/v1") | ||
list.SetKind("DeploymentList") | ||
err := cl.List(nil, list, client.InNamespace("ns1")) | ||
err := cl.List(context.Background(), list, client.InNamespace("ns1")) | ||
Expect(err).To(BeNil()) | ||
Expect(list.Items).To(HaveLen(2)) | ||
}) | ||
|
||
It("should support filtering by labels and their values", func() { | ||
By("Listing deployments with a particular label and value") | ||
list := &appsv1.DeploymentList{} | ||
err := cl.List(nil, list, client.InNamespace("ns1"), | ||
err := cl.List(context.Background(), list, client.InNamespace("ns1"), | ||
client.MatchingLabels(map[string]string{ | ||
"test-label": "label-value", | ||
})) | ||
|
@@ -156,7 +157,7 @@ var _ = Describe("Fake client", func() { | |
Namespace: "ns2", | ||
}, | ||
} | ||
err := cl.Create(nil, newcm) | ||
err := cl.Create(context.Background(), newcm) | ||
Expect(err).To(BeNil()) | ||
|
||
By("Getting the new configmap") | ||
|
@@ -165,7 +166,7 @@ var _ = Describe("Fake client", func() { | |
Namespace: "ns2", | ||
} | ||
obj := &corev1.ConfigMap{} | ||
err = cl.Get(nil, namespacedName, obj) | ||
err = cl.Get(context.Background(), namespacedName, obj) | ||
Expect(err).To(BeNil()) | ||
Expect(obj).To(Equal(newcm)) | ||
Expect(obj.ObjectMeta.ResourceVersion).To(Equal("1")) | ||
|
@@ -187,7 +188,7 @@ var _ = Describe("Fake client", func() { | |
"test-key": "new-value", | ||
}, | ||
} | ||
err := cl.Update(nil, newcm) | ||
err := cl.Update(context.Background(), newcm) | ||
Expect(err).To(BeNil()) | ||
|
||
By("Getting the new configmap") | ||
|
@@ -196,33 +197,33 @@ var _ = Describe("Fake client", func() { | |
Namespace: "ns2", | ||
} | ||
obj := &corev1.ConfigMap{} | ||
err = cl.Get(nil, namespacedName, obj) | ||
err = cl.Get(context.Background(), namespacedName, obj) | ||
Expect(err).To(BeNil()) | ||
Expect(obj).To(Equal(newcm)) | ||
Expect(obj.ObjectMeta.ResourceVersion).To(Equal("2")) | ||
}) | ||
|
||
It("should be able to Delete", func() { | ||
By("Deleting a deployment") | ||
err := cl.Delete(nil, dep) | ||
err := cl.Delete(context.Background(), dep) | ||
Expect(err).To(BeNil()) | ||
|
||
By("Listing all deployments in the namespace") | ||
list := &appsv1.DeploymentList{} | ||
err = cl.List(nil, list, client.InNamespace("ns1")) | ||
err = cl.List(context.Background(), list, client.InNamespace("ns1")) | ||
Expect(err).To(BeNil()) | ||
Expect(list.Items).To(HaveLen(1)) | ||
Expect(list.Items).To(ConsistOf(*dep2)) | ||
}) | ||
|
||
It("should be able to Delete a Collection", func() { | ||
By("Deleting a deploymentList") | ||
err := cl.DeleteAllOf(nil, &appsv1.Deployment{}, client.InNamespace("ns1")) | ||
err := cl.DeleteAllOf(context.Background(), &appsv1.Deployment{}, client.InNamespace("ns1")) | ||
Expect(err).To(BeNil()) | ||
|
||
By("Listing all deployments in the namespace") | ||
list := &appsv1.DeploymentList{} | ||
err = cl.List(nil, list, client.InNamespace("ns1")) | ||
err = cl.List(context.Background(), list, client.InNamespace("ns1")) | ||
Expect(err).To(BeNil()) | ||
Expect(list.Items).To(BeEmpty()) | ||
}) | ||
|
@@ -236,7 +237,7 @@ var _ = Describe("Fake client", func() { | |
Namespace: "ns2", | ||
}, | ||
} | ||
err := cl.Create(nil, newcm, client.CreateDryRunAll) | ||
err := cl.Create(context.Background(), newcm, client.DryRunAll) | ||
Expect(err).To(BeNil()) | ||
|
||
By("Getting the new configmap") | ||
|
@@ -245,7 +246,7 @@ var _ = Describe("Fake client", func() { | |
Namespace: "ns2", | ||
} | ||
obj := &corev1.ConfigMap{} | ||
err = cl.Get(nil, namespacedName, obj) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change is required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When running the linter with staticcheck enabled (not enforced by this PR) it fails with
|
||
err = cl.Get(context.Background(), namespacedName, obj) | ||
Expect(err).To(HaveOccurred()) | ||
Expect(errors.IsNotFound(err)).To(BeTrue()) | ||
Expect(obj).NotTo(Equal(newcm)) | ||
|
@@ -263,7 +264,7 @@ var _ = Describe("Fake client", func() { | |
"test-key": "new-value", | ||
}, | ||
} | ||
err := cl.Update(nil, newcm, client.UpdateDryRunAll) | ||
err := cl.Update(context.Background(), newcm, client.DryRunAll) | ||
Expect(err).To(BeNil()) | ||
|
||
By("Getting the new configmap") | ||
|
@@ -272,7 +273,7 @@ var _ = Describe("Fake client", func() { | |
Namespace: "ns2", | ||
} | ||
obj := &corev1.ConfigMap{} | ||
err = cl.Get(nil, namespacedName, obj) | ||
err = cl.Get(context.Background(), namespacedName, obj) | ||
Expect(err).To(BeNil()) | ||
Expect(obj).To(Equal(cm)) | ||
Expect(obj.ObjectMeta.ResourceVersion).To(Equal("")) | ||
|
@@ -289,7 +290,7 @@ var _ = Describe("Fake client", func() { | |
}, | ||
}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
err = cl.Patch(nil, dep, client.RawPatch(types.StrategicMergePatchType, mergePatch)) | ||
err = cl.Patch(context.Background(), dep, client.RawPatch(types.StrategicMergePatchType, mergePatch)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Getting the patched deployment") | ||
|
@@ -298,7 +299,7 @@ var _ = Describe("Fake client", func() { | |
Namespace: "ns1", | ||
} | ||
obj := &appsv1.Deployment{} | ||
err = cl.Get(nil, namespacedName, obj) | ||
err = cl.Get(context.Background(), namespacedName, obj) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(obj.Annotations["foo"]).To(Equal("bar")) | ||
Expect(obj.ObjectMeta.ResourceVersion).To(Equal("1")) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,7 +122,7 @@ var _ = Describe("controller", func() { | |
By("Invoking Reconciling for Update") | ||
newDeployment := deployment.DeepCopy() | ||
newDeployment.Labels = map[string]string{"foo": "bar"} | ||
newDeployment, err = clientset.AppsV1().Deployments("default").Update(newDeployment) | ||
_, err = clientset.AppsV1().Deployments("default").Update(newDeployment) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(<-reconciled).To(Equal(expectedReconcileRequest)) | ||
|
||
|
@@ -152,7 +152,7 @@ var _ = Describe("controller", func() { | |
By("Invoking Reconciling for an OwnedObject when it is updated") | ||
newReplicaset := replicaset.DeepCopy() | ||
newReplicaset.Labels = map[string]string{"foo": "bar"} | ||
newReplicaset, err = clientset.AppsV1().ReplicaSets("default").Update(newReplicaset) | ||
_, err = clientset.AppsV1().ReplicaSets("default").Update(newReplicaset) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 cool |
||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(<-reconciled).To(Equal(expectedReconcileRequest)) | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -36,7 +36,7 @@ var _ = Describe("runtime signal", func() { | |||
task := &Task{ | ||||
ticker: time.NewTicker(time.Second * 2), | ||||
} | ||||
c := make(chan os.Signal) | ||||
c := make(chan os.Signal, 1) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. context on this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You can see elsewhere in the codebase
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, prevents missing signals, ok. |
||||
signal.Notify(c, os.Interrupt) | ||||
task.wg.Add(1) | ||||
go func(c chan os.Signal) { | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to flip these. Enable all linters and explicitly disable the others, so we know which ones we are disabling and folks can pick up the task of removing a disabled linter from this list if they wanted to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is explicitly called out here because enable-all is deprecated
https://github.com/golangci/golangci-lint/blob/b9eef79121fff235d0d794c176ffa2b3d9bd422f/.golangci.yml#L59-L60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh well, it seems a bit counter intuitive to me, but nothing major