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 checks to use retool. Fix goword and errcheck #7240

Merged
merged 6 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ y.output
profile.coverprofile
explain_test
cmd/explaintest/explain-test.out
_tools/
73 changes: 57 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
PROJECT=tidb
GOPATH ?= $(shell go env GOPATH)

# Ensure GOPATH is set before running build process.
ifeq "$(GOPATH)" ""
$(error Please set the environment variable GOPATH before running `make`)
endif
FAIL_ON_STDOUT := awk '{ print } END { if (NR > 0) { exit 1 } }'

CURDIR := $(shell pwd)
path_to_add := $(addsuffix /bin,$(subst :,/bin:,$(GOPATH)))
Expand All @@ -18,9 +20,10 @@ GOVERALLS := goveralls
ARCH := "`uname -s`"
LINUX := "Linux"
MAC := "Darwin"
PACKAGES := $$(go list ./...| grep -vE "vendor")
FILES := $$(find . -name "*.go" | grep -vE "vendor")
TOPDIRS := $$(ls -d */ | grep -vE "vendor")
PACKAGE_LIST := go list ./...| grep -vE "vendor"
PACKAGES := $$($(PACKAGE_LIST))
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/pingcap/$(PROJECT)/||'
FILES := $$(find $$($(PACKAGE_DIRECTORIES)) -name "*.go" | grep -vE "vendor")

GOFAIL_ENABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|vendor)" | xargs gofail enable)
GOFAIL_DISABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|vendor)" | xargs gofail disable)
Expand Down Expand Up @@ -71,30 +74,68 @@ parserlib: parser/parser.go
parser/parser.go: parser/parser.y
make parser

check: fmt errcheck lint vet
# This is how tools.json is generated
tool-install:
@which retool >/dev/null || go get github.com/twitchtv/retool

# This tool can run other checks in a standardized way
retool add gopkg.in/alecthomas/gometalinter.v2 v2.0.5

# check spelling
# misspell works with gometalinter
retool add github.com/client9/misspell/cmd/misspell v0.3.4
# goword adds additional capability to checking comments
Copy link
Member

Choose a reason for hiding this comment

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

s/checking/check/?

retool add github.com/chzchzchz/goword a9744cb52b033fe5c269df48eeef2c954526cd79

# checks correctness
retool add github.com/gordonklaus/ineffassign 7bae11eba15a3285c75e388f77eb6357a2d73ee2
retool add honnef.co/go/tools/cmd/megacheck master
retool add github.com/dnephin/govet 4a96d43e39d340b63daa8bc5576985aa599885f6

# slow checks
retool add github.com/kisielk/errcheck v1.1.0
retool add github.com/securego/gosec/cmd/gosec 1.0.0

# linter
retool add github.com/mgechev/revive 7773f47324c2bf1c8f7a5500aff2b6c01d3ed73b

check-setup:
Copy link
Member

Choose a reason for hiding this comment

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

Should we add tol-install into this section?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

retool sync installs everything from tools.json. tool-install is the record of how that was generated. Its probably better to put tool-install into a hack/scripts/config folder rather than clutter the Makefile.

@which retool >/dev/null 2>&1 || go get github.com/twitchtv/retool
@retool sync

check: check-setup fmt lint vet

# These need to be fixed before they can be ran regularly
check-fail: goword check-static check-slow
Copy link
Member

Choose a reason for hiding this comment

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

Could you file a github issue for these failed checks? Maybe we can make these checks happy again with the help of the community. 😄


fmt:
@echo "gofmt (simplify)"
@ gofmt -s -l -w $(FILES) 2>&1 | grep -v "vendor|parser/parser.go" | awk '{print} END{if(NR>0) {exit 1}}'
@gofmt -s -l -w $(FILES) 2>&1 | grep -v "vendor|parser/parser.go" | $(FAIL_ON_STDOUT)

goword:
go get github.com/chzchzchz/goword
@echo "goword"
@ goword $(FILES) | awk '{print} END{if(NR>0) {exit 1}}'

errcheck:
go get github.com/kisielk/errcheck
@echo "errcheck"
@ GOPATH=$(GOPATH) errcheck -exclude errcheck_excludes.txt -blank $(PACKAGES) | grep -v "_test\.go" | awk '{print} END{if(NR>0) {exit 1}}'
retool do goword $(FILES) 2>&1 | $(FAIL_ON_STDOUT)

check-static:
@ # vet and fmt have problems with vendor when ran through metalinter
CGO_ENABLED=0 retool do gometalinter.v2 --disable-all --deadline 120s \
--enable misspell \
--enable megacheck \
--enable ineffassign \
$$($(PACKAGE_DIRECTORIES))

check-slow:
CGO_ENABLED=0 retool do gometalinter.v2 --disable-all \
--enable errcheck \
$$($(PACKAGE_DIRECTORIES))
CGO_ENABLED=0 retool do gosec $$($(PACKAGE_DIRECTORIES))

lint:
go get github.com/mgechev/revive
@echo "linting"
CGO_ENABLED=0 revive -formatter friendly -config revive.toml $(PACKAGES)
@CGO_ENABLED=0 retool do revive -formatter friendly -config revive.toml $(PACKAGES)

vet:
@echo "vet"
@ go tool vet -all -shadow $(TOPDIRS) 2>&1 | awk '{print} END{if(NR>0) {exit 1}}'
@retool do govet -all -shadow $$($(PACKAGE_DIRECTORIES)) 2>&1 | $(FAIL_ON_STDOUT)

clean:
$(GO) clean -i ./...
Expand Down
1 change: 1 addition & 0 deletions ast/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package ast_test

import (
Expand Down
41 changes: 41 additions & 0 deletions tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"Tools": [
{
"Repository": "gopkg.in/alecthomas/gometalinter.v2",
"Commit": "46cc1ea3778b247666c2949669a3333c532fa9c6"
},
{
"Repository": "github.com/client9/misspell/cmd/misspell",
"Commit": "7888c6b6ce89353cd98e196bce3c3f9e4cdf31f6"
},
{
"Repository": "github.com/chzchzchz/goword",
"Commit": "a9744cb52b033fe5c269df48eeef2c954526cd79"
},
{
"Repository": "github.com/gordonklaus/ineffassign",
"Commit": "7bae11eba15a3285c75e388f77eb6357a2d73ee2"
},
{
"Repository": "honnef.co/go/tools/cmd/megacheck",
"Commit": "88497007e8588ea5b6baee991f74a1607e809487"
},
{
"Repository": "github.com/dnephin/govet",
"Commit": "4a96d43e39d340b63daa8bc5576985aa599885f6"
},
{
"Repository": "github.com/securego/gosec/cmd/gosec",
"Commit": "5fb530cda357c16175f2c049577d2030de735b28"
},
{
"Repository": "github.com/kisielk/errcheck",
"Commit": "55d8f507faff4d6eddd0c41a3e713e2567fca4e5"
},
{
"Repository": "github.com/mgechev/revive",
"Commit": "7773f47324c2bf1c8f7a5500aff2b6c01d3ed73b"
}
],
"RetoolVersion": "1.3.7"
}