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

tools: linters we could add #1372

Closed
wants to merge 16 commits into from
Closed

tools: linters we could add #1372

wants to merge 16 commits into from

Conversation

ValarDragon
Copy link
Contributor

@ValarDragon ValarDragon commented Jun 25, 2018

This PR adds several linters we can potentially use. Please comment with your thoughts on using the following linters! I've left their errors in the linting step, so we can evaluate how useful they are.

Also take a look here if theres any more linters you think we should run on circle ci: https://github.com/alecthomas/gometalinter

Closes #1084
I've left the errors in linting to make it easier to judge whether its something we want to use. Once we decide which ones to keep, I'll update the make file and make test_lint accordingly.

Changelog also needs to be updated, will do once we decide on which linters to use.
Also remember, if we agree with a linter in most places, but not in a couple, we should still use it, and just add nolint in the places we disagree. (nolint can be extended to cover an entire file iirc too)

  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG.md
  • Updated Gaia/Examples
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@ValarDragon ValarDragon requested a review from cwgoes June 25, 2018 21:36
@ValarDragon ValarDragon changed the title tools: add go vet tools: linters we could add Jun 25, 2018
@codecov
Copy link

codecov bot commented Jun 25, 2018

Codecov Report

Merging #1372 into develop will decrease coverage by 0.92%.
The diff coverage is 35.93%.

@@             Coverage Diff             @@
##           develop    #1372      +/-   ##
===========================================
- Coverage    62.81%   61.88%   -0.93%     
===========================================
  Files          109      103       -6     
  Lines         6016     5864     -152     
===========================================
- Hits          3779     3629     -150     
+ Misses        2020     2018       -2     
  Partials       217      217

@ValarDragon
Copy link
Contributor Author

For some reason, all the output doesn't show on circle CI. So check out the following ghost bin for the sample error: https://ghostbin.com/paste/cpdaz

@cwgoes
Copy link
Contributor

cwgoes commented Jun 26, 2018

Can we ensure that local output and CI output are the same and add a make lint target so that developers can check linter output without waiting for CI?

@ValarDragon
Copy link
Contributor Author

Will do. I'll add a make test_lint command to this PR, but I'd rather we decide which linters to use first before making the command.

@cwgoes
Copy link
Contributor

cwgoes commented Jun 26, 2018

Will do. I'll add a make test_lint command to this PR, but I'd rather we decide which linters to use first before making the command.

That's fine - but ideally we avoid special-casing the CircleCI config; CircleCI should just run make get_tools lint.

@UnitylChaos
Copy link
Contributor

I'm all for maximal metalinting 👍

@cwgoes cwgoes mentioned this pull request Jun 26, 2018
6 tasks
@rigelrozanski
Copy link
Contributor

unparam is really cool - we don't pass unparam right now aka there are a few limp-dead variables

@ValarDragon
Copy link
Contributor Author

I'm conflicted on whether or not deadcode is useful. Here is its output:

baseapp/baseapp.go:26:1:warning: dbHeaderKey is unused (deadcode)
cmd/gaia/cmd/gaiadebug/hack.go:94:1:warning: base64ToPub is unused (deadcode)
cmd/gaia/cmd/gaiadebug/hack.go:117:1:warning: DefaultCLIHome is unused (deadcode)
cmd/gaia/cmd/gaiadebug/hack.go:117:1:warning: DefaultNodeHome is unused (deadcode)
server/test_helpers.go:34:1:warning: setupViper is unused (deadcode)
types/int.go:34:1:warning: mod is unused (deadcode)
types/lib/linear.go:245:1:warning: subspace is unused (deadcode)
x/gov/test_common.go:21:1:warning: getMockApp is unused (deadcode)
x/slashing/wire.go:12:1:warning: cdcEmpty is unused (deadcode)
x/slashing/test_common.go:25:1:warning: pks is unused (deadcode)
x/slashing/test_common.go:49:1:warning: createTestInput is unused (deadcode)
x/slashing/test_common.go:92:1:warning: newTestMsgCreateValidator is unused (deadcode)
x/stake/keeper/test_common.go:25:1:warning: addrDels is unused (deadcode)
x/stake/keeper/test_common.go:25:1:warning: emptyPubkey is unused (deadcode)
x/stake/keeper/test_common.go:25:1:warning: addrVals is unused (deadcode)
x/stake/keeper/test_common.go:25:1:warning: emptyAddr is unused (deadcode)
x/stake/types/test_common.go:13:1:warning: emptyAddr is unused (deadcode)
x/stake/types/test_common.go:13:1:warning: addr2 is unused (deadcode)
x/stake/types/test_common.go:13:1:warning: emptyPubkey is unused (deadcode)
x/stake/types/test_common.go:13:1:warning: addr3 is unused (deadcode)

It gave a couple of useful points, e.g. baseapp/baseapp.go:26:1:warning: dbHeaderKey is unused (deadcode), means we should either remove that or write a test case to cover that. But the majority of the output is for unused vars in test helper files, which I don't think is code that we need to change. We'd have to add a bunch of nolint statements to the test files though. I'm leaning towards removing deadcode.

@ValarDragon
Copy link
Contributor Author

ValarDragon commented Jun 27, 2018

Looks like structcheck doesn't do what we want. It only checks at the module level, not at the whole project level. This may be something that can be fixed though. I'm going to remove it from here for now, until a better tool / structcheck has been forked. I'll remove deadcode too, we can always add it back if we like its output.

@ValarDragon
Copy link
Contributor Author

Note, I've disabled errcheck output on the client directories. This was because the errors there don't really contribute to failing fast / aren't that helpful. (i.e. not checking errors on writing the http responses)

@rigelrozanski
Copy link
Contributor

rigelrozanski commented Jun 27, 2018

@ValarDragon As mentioned on our call two days ago - we should close this PR and open an issue which contains all the linters (and discussions) - then we should open up individual PRs for each linter being added which simultaneously adds the linter as well as fixes all bugs which the linter pointed out

  • want to take this on? - we should probably copy all the comments from this PR into the issue as well

@cwgoes cwgoes deleted the dev/go_vet branch June 28, 2018 17:12
@ValarDragon ValarDragon restored the dev/go_vet branch June 28, 2018 19:02
@ValarDragon ValarDragon deleted the dev/go_vet branch July 6, 2018 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reorder variables structs to optimize memory Check for unused function inputs
4 participants