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 gometalinter errcheck to pre-commit-hook, fix all Go unchecked errors. #2885

Merged
merged 5 commits into from
Jul 18, 2017

Conversation

helinwang
Copy link
Contributor

No description provided.

@helinwang helinwang changed the title add error check to pre-commit-hook, fix all go unchecked errors. Add error check to pre-commit-hook, fix all go unchecked errors. Jul 14, 2017
@helinwang helinwang changed the title Add error check to pre-commit-hook, fix all go unchecked errors. Add error check to pre-commit-hook, fix all Go unchecked errors. Jul 14, 2017
@helinwang helinwang changed the title Add error check to pre-commit-hook, fix all Go unchecked errors. Add gometalinter errcheck to pre-commit-hook, fix all Go unchecked errors. Jul 14, 2017
@helinwang helinwang force-pushed the handle_err branch 6 times, most recently from d7adc54 to 08e7d2a Compare July 15, 2017 00:13
Copy link
Collaborator

@wangkuiyi wangkuiyi left a comment

Choose a reason for hiding this comment

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

Cool change!

@@ -13,6 +13,12 @@ export PATH=/usr/bin:$PATH
pre-commit install
clang-format --version

# set up go environment for running gometalinter
Copy link
Collaborator

Choose a reason for hiding this comment

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

Who would call check_style.sh?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh. I see. I recommended to call check_style.sh from Travis CI.

Copy link
Collaborator

@wangkuiyi wangkuiyi left a comment

Choose a reason for hiding this comment

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

LGTM!

@helinwang helinwang force-pushed the handle_err branch 4 times, most recently from 3c78242 to beae398 Compare July 15, 2017 01:40
hooks:
- id: go-fmt
files: (.*\.go)
types: [go]
- id: go-lint
Copy link
Contributor

Choose a reason for hiding this comment

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

用了gometalinter应该就不用再单独使用golint了。
https://github.com/alecthomas/gometalinter#quickstart

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gongweibao done.


echo "gopath: $GOPATH"
echo "pwd: `pwd`"
find ./go
Copy link
Contributor

Choose a reason for hiding this comment

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

这个是做什么?是测试代码?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe @helinwang wants to listing the directory to log file. That's reasonable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gongweibao @dzhwinter 不好意思,是测试的,不知为何在我本地能运行,在travis不行,加了写代码测试了一下。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gongweibao @dzhwinter all removed, found the issue:
go tool的对象代码(比如go build xxx)最好是在$GOPATH里面,不然会有各种问题(vendor directory ignored, no caching of built object files...)。我是调travis gometalinter的时候出现的这个问题,如果运行对象不在$GOPATH中,gometalinter一直过不了。改成了这样才过的:https://github.com/PaddlePaddle/pre-commit-golang/blob/master/run-gometalinter.sh#L5

echo "gopath: $GOPATH"
echo "pwd: `pwd`"
find ./go
cd go; gometalinter --vendor --disable-all --enable errcheck ./...; cd -
Copy link
Contributor

@gongweibao gongweibao Jul 15, 2017

Choose a reason for hiding this comment

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

cd go; gometalinter --vendor --disable-all --enable=errcheck --enable=golint ./... ; cd -

Copy link
Contributor

Choose a reason for hiding this comment

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

我们是否也把vet检查加上?

Copy link
Contributor Author

@helinwang helinwang Jul 15, 2017

Choose a reason for hiding this comment

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

@gongweibao go vet 有一些正确的地方过不了。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the message showing go vet fails:

gometalinter --vendor --disable-all --enable errcheck --enable vet --enable golint ./...
master/c/client.go:26::error: possible misuse of unsafe.Pointer (vet)
pserver/optimizer.go:17::error: possible misuse of unsafe.Pointer (vet)
pserver/client/c/cclient.go:37::error: possible misuse of unsafe.Pointer (vet)

Copy link
Contributor Author

@helinwang helinwang Jul 17, 2017

Choose a reason for hiding this comment

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

@gongweibao , 修复了,其实go vet都报对了。加上go vet了。

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@dzhwinter dzhwinter left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -219,7 +219,7 @@ func (s *Service) GetParam(name string, parameter *Parameter) error {
}

// pserver save checkpoint
func (s *Service) doCheckpoint() error {
func (s *Service) doCheckpoint() (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

a smart feature of named return value!
seems that I ignored so much return error when saving the checkpoint.


echo "gopath: $GOPATH"
echo "pwd: `pwd`"
find ./go
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe @helinwang wants to listing the directory to log file. That's reasonable.


echo "gopath: $GOPATH"
echo "pwd: `pwd`"
find ./go
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to filter out the vendor package file. change to

find ./go  -not -path "./go/vendor/*"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dzhwinter good point! Please see https://github.com/PaddlePaddle/pre-commit-golang/blob/master/run-gometalinter.sh , --vendor already ignore the vendor folder.

Copy link
Contributor

Choose a reason for hiding this comment

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

get it.

Unchecked errors could be handled by: cd go; gometalinter --vendor --disable-all --enable errcheck $(glide nv)
@helinwang helinwang force-pushed the handle_err branch 2 times, most recently from faa803b to c791f90 Compare July 17, 2017 20:41
Copy link
Contributor

@gongweibao gongweibao left a comment

Choose a reason for hiding this comment

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

LGTM

@helinwang helinwang merged commit 2db1b68 into PaddlePaddle:develop Jul 18, 2017
@helinwang helinwang deleted the handle_err branch July 18, 2017 06:06
heavengate pushed a commit to heavengate/Paddle that referenced this pull request Aug 16, 2021
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.

4 participants