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

apply the megacheck code vetting tool for idiomatic go #3949

Merged
merged 7 commits into from Jun 7, 2017

Conversation

Projects
None yet
3 participants
@zramsay
Copy link
Contributor

zramsay commented May 31, 2017

  • megacheck applies each of the unused, gosimple, and staticcheck tools to the code base in order to enforce idiomatic golang. See here for more information.
  • Only the least controversial recommendations were applied, e.g., some unused functions were left as they may have an intended use. Unused variables were commented out to reduce the number of recommendations provided by the tool. Other recommended changes I skipped because the concepts are new to me.

Main Changes

  • error handling: if err != nil { return err }; return nil was simplified to return err
  • bool checks: if pin == false is the same as if !pin
  • replaced the deprecated os.SEEK_* with io.Seek*
  • specifying the capacity in a make() was dropped if set to the same as its length.
  • replaced time.Now().Sub with time.Since()
  • for loops that could be replaced with append(a, b...), were

zramsay added some commits May 31, 2017

introduce 'make megacheck'
License: MIT
Signed-off-by: Zach Ramsay <zach.ramsay@gmail.com>
apply the megacheck tool to improve code quality
License: MIT
Signed-off-by: Zach Ramsay <zach.ramsay@gmail.com>
@zramsay

This comment has been minimized.

Copy link
Contributor

zramsay commented Jun 1, 2017

the failure on codeclimate is a false positive (calling context.TODO() is valid and not equal to // TODO). I've submitted a ticket to them.

errApiVersionMismatch = errors.New("api version mismatch")
errRequestCanceled = errors.New("request canceled")
// errUnexpectedApiOutput = errors.New("api returned unexpected output")
// errApiVersionMismatch = errors.New("api version mismatch")

This comment has been minimized.

@whyrusleeping

whyrusleeping Jun 1, 2017

Member

if its actually not being used, should probably just remove it

This comment has been minimized.

@zramsay

zramsay Jun 1, 2017

Contributor

roger.

@@ -99,7 +100,7 @@ func run(ipfsPath, watchPath string) error {
}

interrupts := make(chan os.Signal)
signal.Notify(interrupts, os.Interrupt, os.Kill)
signal.Notify(interrupts, os.Interrupt, syscall.SIGTERM)

This comment has been minimized.

@whyrusleeping

whyrusleeping Jun 1, 2017

Member

is os.Kill deprecated?

This comment has been minimized.

@zramsay

zramsay Jun 1, 2017

Contributor

the error message is: os.Kill cannot be trapped (did you mean syscall.SIGTERM?) (SA1016) where SA1016 -> Trapping a signal that cannot be trapped

@@ -45,7 +45,7 @@ func TestClientFindProviders(t *testing.T) {
providersFromClient := client.FindProvidersAsync(context.Background(), k, max)
isInClient := false
for pi := range providersFromClient {
if pi.ID == pi.ID {
if pi.ID == pi.ID { // <-- typo?

This comment has been minimized.

@whyrusleeping

whyrusleeping Jun 1, 2017

Member

this code is so old and unused... We can probably just remove routing/mock and the supernode routing stuff in general (as a separate PR)

This comment has been minimized.

@zramsay
@whyrusleeping
Copy link
Member

whyrusleeping left a comment

This looks great, thanks!

Could you go ahead and just delete the things you commented out in a separate commit (so i don't have to re-read the entire diff again)

@whyrusleeping

This comment has been minimized.

Copy link
Member

whyrusleeping commented Jun 1, 2017

~~~Also, if you don't mind, could you address the codeclimate issues? (if they feel like 'not my problem' then go ahead and skip them, its a bit aggressive on what it wants you to do)~~~

nvm, read your comment

@zramsay

This comment has been minimized.

Copy link
Contributor

zramsay commented Jun 1, 2017

sounds good, will address. What value is the codeclimate integration providing over and above implementing this TODO ? IMO the integration should be dropped in favour of implementing that as part of make test (see last line on original PR comment). Happy to pick that up as a seperate PR

@zramsay zramsay force-pushed the zramsay:fix/codebase-consistency branch from b235cb4 to 11d38be Jun 1, 2017

address PR comments; remove commented/dead code
License: MIT
Signed-off-by: Zach Ramsay <zach.ramsay@gmail.com>

@zramsay zramsay force-pushed the zramsay:fix/codebase-consistency branch from 11d38be to 096b323 Jun 1, 2017

Rules.mk Outdated
@go get honnef.co/go/tools/cmd/megacheck
@for pkg in ${PACKAGES_NOVENDOR}; do megacheck "$$pkg"; done

.PHONY: megacheck

This comment has been minimized.

@Kubuxu

Kubuxu Jun 1, 2017

Member

Please add this target to mk/golang.mk instead and add comment about it to help print section.

This comment has been minimized.

@zramsay

zramsay Jun 1, 2017

Contributor

done

@@ -189,104 +186,3 @@ func genOpSet(seed int64, keep, temp []string) []testOp {
}
}
}

// executes the given op set with a repl to allow easier debugging
func debugExecuteOpSet(ds dag.DAGService, width int, ops []testOp) (*HamtShard, error) {

This comment has been minimized.

@Kubuxu

Kubuxu Jun 1, 2017

Member

This probably shouldn't be removed. It could be useful hot-plug debugging tool.

cc @whyrusleeping

This comment has been minimized.

@zramsay

zramsay Jun 1, 2017

Contributor

reinstated it but commented it out

@zramsay zramsay force-pushed the zramsay:fix/codebase-consistency branch from 37601a3 to 31f92ab Jun 1, 2017

zramsay added some commits Jun 1, 2017

codeclimate: use only 4/5 defaults
because context.TODO() is a legit function

License: MIT
Signed-off-by: Zach Ramsay <zach.ramsay@gmail.com>
make: use correct location for [test_go_megacheck]
License: MIT
Signed-off-by: Zach Ramsay <zach.ramsay@gmail.com>
hamt: reinstate a useful debug function
License: MIT
Signed-off-by: Zach Ramsay <zach.ramsay@gmail.com>

@zramsay zramsay force-pushed the zramsay:fix/codebase-consistency branch from 31f92ab to b77d5aa Jun 1, 2017

@zramsay

This comment has been minimized.

Copy link
Contributor

zramsay commented Jun 1, 2017

circle will probably pass after re-triggered. I've notice some non-determinism with the tests (e.g., jenkins failed randomly on a commit where the only change was to .codeclimate.yml

@Kubuxu

This comment has been minimized.

Copy link
Member

Kubuxu commented Jun 1, 2017

Test are deterministic just build machines of free service providers sometimes hang on our network tests.

@@ -664,11 +664,6 @@ stat' on the file or any of its ancestors.
return
}

var r io.Reader = input
if countfound {
r = io.LimitReader(r, int64(count))

This comment has been minimized.

@whyrusleeping

whyrusleeping Jun 3, 2017

Member

Hrm... Maybe you discovered a bug here. I think the copy below was supposed to be from 'r' instead of 'input'

This comment has been minimized.

@zramsay

zramsay Jun 3, 2017

Contributor

makes sense. The tests are happy with the fix.

bugfix: copy the correct variable
License: MIT
Signed-off-by: Zach Ramsay <zach.ramsay@gmail.com>

@zramsay zramsay force-pushed the zramsay:fix/codebase-consistency branch from a9c5ba5 to 6c064d1 Jun 3, 2017

@whyrusleeping

This comment has been minimized.

Copy link
Member

whyrusleeping commented Jun 7, 2017

@zramsay Thanks a bunch! This is really useful :) If there are more, feel free to file more PRs

@whyrusleeping whyrusleeping merged commit eef022c into ipfs:master Jun 7, 2017

6 of 7 checks passed

continuous-integration/jenkins/pr-merge This commit cannot be built
Details
ci/circleci Your tests passed on CircleCI!
Details
codeclimate 216 fixed issues
Details
codecov/patch 74.57% of diff hit (target 35.39%)
Details
codecov/project 63.77% (+28.38%) compared to 20dae52
Details
commit-message-check/gitcop All commit messages are valid
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@zramsay

This comment has been minimized.

Copy link
Contributor

zramsay commented Jun 7, 2017

no problem! There a couple dozen ~more complex fixes that I'll tackle as part of #3953

@zramsay zramsay deleted the zramsay:fix/codebase-consistency branch Jun 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment