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

🏃 Update linter and lint fixes #773

Merged
merged 1 commit into from Feb 21, 2020

Conversation

mcristina422
Copy link
Contributor

@mcristina422 mcristina422 commented Jan 22, 2020

This updates golangci-lint, moves the configuration all to .golangci.yml and then fixes the linter errors

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 22, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @mcristina422. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 22, 2020
Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of questions, but mostly looks awesome.

Thanks so much!

@@ -86,7 +86,7 @@ func (e *Etcd) setProcessState() error {
return err
}

e.processState.StartMessage = internal.GetEtcdStartMessage(e.processState.URL)
e.processState.HealthCheckEndpoint = "/health"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o_O

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StartMessage is deprecated. So staticcheck is failing. I was iffy on this change too, we can add //nolint to revert this change

https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/internal/testing/integration/internal/process.go#L40

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context on this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SA1017: the channel used with signal.Notify should be buffered
https://staticcheck.io/docs/checks#SA1017

You can see elsewhere in the codebase

c := make(chan os.Signal, 2)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, prevents missing signals, ok.

@gerred gerred mentioned this pull request Jan 23, 2020
Copy link

@kensipe kensipe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a big fan of most of the code changes... they make sense.

The exception is etcd.go L89 change for which I don't at the moment understand the impact.

I'm most concern with the dropping of a number of enabled linters. Is the situation such that this PR would be too large to handle the update for all of them? or is it realized that these are dropped? or ? I think we need clear intention defined here.

.golangci.yml Outdated
@@ -3,3 +3,5 @@ linters-settings:
line-length: 170
dupl:
threshold: 400
run:
deadline: 5m
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deadline is deprecated... we should switch to timeout

details: golangci/golangci-lint#822

# --enable=gosec \
# --enable=maligned \
# --enable=safesql \
golangci-lint run ./pkg/... ./examples/... .
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following linters have been removed and are NOT enabled by default

--enable=misspell \	   
   --enable=golint \	
   --enable=goconst \	
   --enable=unparam \	
   --enable=nakedret \	
   --enable=interfacer \	
   --enable=gocyclo \	
   --enable=lll \	
   --enable=dupl \	
   --enable=goimports \

Is this intended? If we plan to keep them... it would be great to add them to the .golangci.yml file.

https://github.com/golangci/golangci-lint#enabled-by-default-linters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this was not my intention. I misinterpreted how dropping the --disable-all flag worked. I'll make sure to explicitly enable the same ones in the config file

@vincepri
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 23, 2020
Copy link

@kensipe kensipe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcristina422 might I suggest that you change the one contested change around e.processState.HealthCheckEndpoint = "/health" adding a //nolint: there and we can have that debate separately?

The rest of this lgtm

@mcristina422
Copy link
Contributor Author

@kensipe I've reverted the etcd change. Since staticcheck isn't enabled currently this will pass linting

In a follow up we can debate enabling more like staticcheck, stylecheck, whitespace and others found in the more strict configuration that golangci uses themselves https://github.com/golangci/golangci-lint/blob/master/.golangci.yml

Copy link

@kensipe kensipe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 23, 2020
@kensipe
Copy link

kensipe commented Jan 24, 2020

@DirectXMan12 could we get a 2nd look on this?

@@ -74,7 +74,7 @@ function fetch_go_tools {
header_text "Checking for gometalinter.v2"
if ! is_installed golangci-lint; then
header_text "Installing golangci-lint"
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.21.0
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.23.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

long term maybe we introduce a tools.go to manage these dependencies with go modules - a few other tools do this.

@DirectXMan12 DirectXMan12 self-assigned this Feb 5, 2020
@kensipe
Copy link

kensipe commented Feb 11, 2020

@mcristina422 looks like it needs a rebase... lets see if we can get some attention on this after the rebase... thx

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 11, 2020
@@ -235,7 +236,7 @@ var _ = Describe("Fake client", func() {
Namespace: "ns2",
}
obj := &corev1.ConfigMap{}
err = cl.Get(nil, namespacedName, obj)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

SA1012: do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use (staticcheck)

https://staticcheck.io/docs/checks#SA1012

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 cool

@@ -24,29 +24,6 @@ go vet ${MOD_OPT} ./...

header_text "running golangci-lint"

golangci-lint run --disable-all \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 cool

linters-settings:
lll:
line-length: 170
dupl:
threshold: 400

run:
timeout: 5m
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 cool

@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Feb 11, 2020
@@ -1,5 +1,27 @@
linters:
disable-all: true
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shows great for me 👍
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 11, 2020
@vincepri
Copy link
Member

/approve

@vincepri vincepri added this to the v0.5.x milestone Feb 21, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mcristina422, vincepri

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 21, 2020
@k8s-ci-robot k8s-ci-robot merged commit e00985b into kubernetes-sigs:master Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants