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

Switch linter from gometalinter to golangci-lint #176

Merged
merged 6 commits into from
May 29, 2019

Conversation

corneliusweig
Copy link
Contributor

@corneliusweig corneliusweig commented May 8, 2019

Close #174
Based on #178

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 8, 2019
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 8, 2019
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 8, 2019
@corneliusweig corneliusweig marked this pull request as ready for review May 8, 2019 22:15
@corneliusweig corneliusweig changed the title WIP Switch linter from gometalinter to golangci-lint Switch linter from gometalinter to golangci-lint May 8, 2019
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 8, 2019
@codecov-io
Copy link

codecov-io commented May 8, 2019

Codecov Report

Merging #176 into master will not change coverage.
The diff coverage is 66.66%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #176   +/-   ##
=======================================
  Coverage   50.91%   50.91%           
=======================================
  Files          13       13           
  Lines         711      711           
=======================================
  Hits          362      362           
  Misses        297      297           
  Partials       52       52
Impacted Files Coverage Δ
pkg/environment/environment.go 77.27% <ø> (ø) ⬆️
pkg/version/version.go 100% <ø> (ø) ⬆️
pkg/installation/upgrade.go 0% <0%> (ø) ⬆️
pkg/installation/install.go 35.16% <100%> (ø) ⬆️
pkg/download/downloader.go 68.04% <100%> (ø) ⬆️
pkg/installation/move.go 32.55% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ac6aa0...1442b8a. Read the comment docs.

@ahmetb
Copy link
Member

ahmetb commented May 8, 2019

I think the commits from other rename PR got in here, too. Please rebase once the other one merges.

@corneliusweig
Copy link
Contributor Author

@ahmetb done

@ahmetb
Copy link
Member

ahmetb commented May 8, 2019

Thanks for proposing this. I feel a bit uneasy about hack/install_golangci-lint.sh which is auto-generated, long and doesn't seem maintainable.

I think we shouldn't use megalinters like this one either. I'm not sure if the value add is enough.

I'm trying to understand what other kubernetes projects use. Here's a search query: https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes+%5Cblint+-file:vendor

I suspect falling back to x/lint and go vet for now would suffice. What do you think of this?

@ahmetb
Copy link
Member

ahmetb commented May 8, 2019

@corneliusweig
Copy link
Contributor Author

I'm not sure I understand your concerns about a metalinter, after all gometalinter was one too. I understand your worries about the generated script, though. I had another look at the golangci-lint docs and they offer an install script for CI environments. For example, kustomize also uses that https://github.com/kubernetes-sigs/kustomize/blob/540e4023dae93dc9d8fcab37b18734ef9df08339/.travis.yml#L31

Would that address your worries?

@corneliusweig
Copy link
Contributor Author

However, this would mean that users can't run the linter locally without installing golangci-lint manually.

@ahmetb
Copy link
Member

ahmetb commented May 9, 2019

The part that annoyed me slightly is why there's a need for a very long general-purpose script (install_golangci-lint.sh) just to install a go binary?

Can't we just do wget+untar? I know their readme says "use this script" but I don't see the point just yet.

@corneliusweig
Copy link
Contributor Author

Well I think the major argument for this script is convenience for users with different platforms and architectures. The script conveniently downloads the correct build for the current platform. As a new contributor, I would find it very nice if the linter would just work without having to manually download that binary from wherever that is.
Another issue is consistency of linter warnings. The reported issues do change slightly with each version. Pinning the linter version avoids confusion here.

Admittedly, the script is large. But it does have a purpose. (Plus it also checks the hashsum)

@corneliusweig corneliusweig force-pushed the pr/golangci-lint branch 2 times, most recently from e0d422a to 00f4513 Compare May 9, 2019 19:19
@ahmetb
Copy link
Member

ahmetb commented May 9, 2019

Yeah but we could write our own install script and it would download if the binary is not in $PATH from the pinned version. I suspect the script would be very short and maintainable if we wrote it.

Having wget/tar installed is a sensible expectation from any contributor so I’m not too worried about it. We already use sha256sum tooling in other scripts.

@corneliusweig
Copy link
Contributor Author

corneliusweig commented May 9, 2019

Honestly, if we want to support contributors on different platforms, this script is the best way to go. After all, it's been tried and tested.

I feel you major concern is having the script in the repo. Would it be an option to run it as curl http:... | sh - and take the hosted file directly from github? I think it should also be possible to pin the version.

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 10, 2019
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 10, 2019
@ahmetb
Copy link
Member

ahmetb commented May 10, 2019

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 10, 2019
@@ -15,8 +15,10 @@
// Package version contains the version information of the krew binary.
package version

const unknown = "unknown"
Copy link
Member

Choose a reason for hiding this comment

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

I don't know why this is a linter error. It’s pretty common coding practice to have package level-consts that are used throughout the code rather than duplicating it.

Another example is below. We should probably turn off this linter, it’s too aggressive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't quite understand what you mean. Travis and my machine think that the linter passes.

Do you mean that the constant should not be there and be inlined instead? This is what the linter complained about so I extracted the constants. If you think this is bad, I can see what linter needs to be disabled.

Copy link
Member

Choose a reason for hiding this comment

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

ah, wait, I now see that the linter is actually trying to help us.

that said, it's erroneous. the "unknown" string on both gitCommit() and gitTag() methods mean different things. so they should not be shared by the same variable. we can do:

const unknownGitCommit = "unknown"
const unknownGitTag = "unknown"

similarly, the tests below actually test against v != unknown which isn't good.

When we update the value of the const, we might be breaking the API (in this case we aren't), but the if test continues to test v != "unknown" literal string comparison, it could catch that.

So I think we should still disable this particular linter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. I disabled the goconst linter. I think it would have allowed two occurrences of "unknown" in tests, but goconst is not critical at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ahmetb can you take another look or close this PR?

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 10, 2019
@@ -16,6 +16,8 @@ package version

import "testing"

const commitSha = "abcdef"
Copy link
Member

Choose a reason for hiding this comment

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

Can you revert changes to this file? We since removed this linter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. PTAL

@ahmetb
Copy link
Member

ahmetb commented May 29, 2019

/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 May 29, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmetb, corneliusweig

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 May 29, 2019
@k8s-ci-robot k8s-ci-robot merged commit 377dfae into kubernetes-sigs:master May 29, 2019
@corneliusweig corneliusweig deleted the pr/golangci-lint branch May 29, 2019 21:34
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.

Switch linter to golangci-lint
4 participants