-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
d7adc54
to
08e7d2a
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
3c78242
to
beae398
Compare
.pre-commit-config.yaml
Outdated
hooks: | ||
- id: go-fmt | ||
files: (.*\.go) | ||
types: [go] | ||
- id: go-lint |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gongweibao done.
paddle/scripts/travis/check_style.sh
Outdated
|
||
echo "gopath: $GOPATH" | ||
echo "pwd: `pwd`" | ||
find ./go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是做什么?是测试代码?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gongweibao @dzhwinter 不好意思,是测试的,不知为何在我本地能运行,在travis不行,加了写代码测试了一下。
There was a problem hiding this comment.
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
paddle/scripts/travis/check_style.sh
Outdated
echo "gopath: $GOPATH" | ||
echo "pwd: `pwd`" | ||
find ./go | ||
cd go; gometalinter --vendor --disable-all --enable errcheck ./...; cd - |
There was a problem hiding this comment.
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 -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们是否也把vet
检查加上?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gongweibao go vet
有一些正确的地方过不了。
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
paddle/scripts/travis/check_style.sh
Outdated
|
||
echo "gopath: $GOPATH" | ||
echo "pwd: `pwd`" | ||
find ./go |
There was a problem hiding this comment.
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.
paddle/scripts/travis/check_style.sh
Outdated
|
||
echo "gopath: $GOPATH" | ||
echo "pwd: `pwd`" | ||
find ./go |
There was a problem hiding this comment.
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/*"
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
faa803b
to
c791f90
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.