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

Add a staticcheck verify script and fix errors #242

Merged
merged 1 commit into from
Aug 30, 2019

Conversation

codenrhoden
Copy link
Contributor

What this PR does / why we need it:
I figured since k/k now has support for running staticcheck, we should do it on our projects.

This patch adds a hack/verify-staticcheck.sh script, adds a Makefile
target for "make staticcheck", and fixes the errors found.

A couple of the other check scripts (format, lint) or modified to no
longer use GO111MODULE=off when they "go get" the needed tools. That
was there before to avoid having go.mod change when running the
scripts, but instead this patch just allows in the needed changes to
go.mod and the correct version should be installed every time. no need
to fight the tool. The go get commands are still needed in the
scripts, however, even if a go mod download has been done, because the
download won't install the tool, but go get will.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:
The initial list of errors found were:

cmd/vcpctl/provision/provision.go:40:2: var datacenter is unused (U1000)
cmd/vcpctl/provision/provision.go:42:2: var secretName is unused (U1000)
cmd/vcpctl/provision/provision.go:44:2: var secretNamespace is unused (U1000)
pkg/cli/cli.go:89:10: this value of err is never used (SA4006)
pkg/cli/user.go:44:2: field password is unused (U1000)
pkg/cloudprovider/vsphere/cloud.go:151:2: should merge variable declaration with assignment on next line (S1021)
pkg/common/config/config.go:438:4: this value of insecure is never used (SA4006)
pkg/common/connectionmanager/search.go:103:7: should omit comparison to bool constant, can be simplified to found (S1002)
pkg/common/connectionmanager/search.go:148:8: should omit comparison to bool constant, can be simplified to found (S1002)
pkg/common/connectionmanager/search.go:279:7: should omit comparison to bool constant, can be simplified to found (S1002)
pkg/common/connectionmanager/search.go:324:8: should omit comparison to bool constant, can be simplified to found (S1002)
pkg/common/connectionmanager/zones.go:178:7: should omit comparison to bool constant, can be simplified to found (S1002)
pkg/common/connectionmanager/zones.go:223:8: should omit comparison to bool constant, can be simplified to found (S1002)
pkg/common/connectionmanager/zones.go:330:36: should use make(map[string]string) instead (S1019)
pkg/common/vclib/pbm.go:68:6: should omit nil check; len() for nil slices is defined as zero (S1009)
pkg/common/vclib/utils.go:41:2: should use 'return <expr>' instead of 'if <expr> { return <bool> }; return <bool>' (S1008)
pkg/common/vclib/utils.go:130:15: should use raw string (`...`) with regexp.MustCompile to avoid having to escape twice (S1007)
pkg/common/vclib/virtualmachine.go:220:2: should replace loop with dsRefList = append(dsRefList, hostSystemMo.Datastore...) (S1011)
pkg/common/vclib/virtualmachine.go:292:3: should merge variable declaration with assignment on next line (S1021)

Release note:

NONE

/assign @andrewsykim
/assign @dvonthenen

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 28, 2019
@codenrhoden
Copy link
Contributor Author

If we think this might cause conflicts with #241, let's wait on it until after that goes in.

Also, do we even think this is a good idea?

@davidvonthenen
Copy link
Contributor

I think the "unused" stuff could be quite useful in helping remove dead/unreferenced code. The "should omit comparison to bool constant" is nit but meh.

I think the benefits of dead code removal is worth it.

@codenrhoden
Copy link
Contributor Author

/hold
Will keep this held until David's PR goes in, so I can rebase and look for anything new.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 28, 2019
@davidvonthenen
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 28, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dvonthenen

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 Aug 28, 2019
This patch adds a hack/verify-staticcheck.sh script, adds a Makefile
target for "make staticcheck", and fixes the errors found.

A couple of the other check scripts (format, lint) or modified to no
longer use `GO111MODULE=off` when they "go get" the needed tools. That
was there before to avoid having `go.mod` change when running the
scripts, but instead this patch just allows in the needed changes to
go.mod and the correct version should be installed every time. no need
to fight the tool. The `go get` commands are still needed in the
scripts, however, even if a `go mod download` has been done, because the
download won't install the tool, but `go get` will.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 30, 2019
@codenrhoden
Copy link
Contributor Author

/hold cancel
@dvonthenen this is ready for your re-review. I rebased it after your new stuff went in.

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 30, 2019
@davidvonthenen
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 30, 2019
@k8s-ci-robot k8s-ci-robot merged commit f11e58a into kubernetes:master Aug 30, 2019
@codenrhoden codenrhoden deleted the staticcheck branch August 30, 2019 18:01
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. 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.

4 participants