From 22fb4dfc30f9153a2943d183819de0cb2e5d8d90 Mon Sep 17 00:00:00 2001 From: b00ris Date: Mon, 23 Oct 2017 13:21:30 +0300 Subject: [PATCH 1/2] integrate linters into travis --- .travis.yml | 10 ++-- Makefile | 58 ++-------------------- static/config/linter_exclude_list.txt | 0 static/tools/mk/lint.mk | 70 +++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 58 deletions(-) delete mode 100644 static/config/linter_exclude_list.txt create mode 100644 static/tools/mk/lint.mk diff --git a/.travis.yml b/.travis.yml index e19863b06..5b4bd3c8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,14 @@ dist: trusty install: - go get golang.org/x/tools/cmd/cover + - make lint-deps -script: - - make ci - +jobs: + include: + - stage: lint + script: make lint + - stage: ci + script: make ci cache: directories: - .ethereumtest diff --git a/Makefile b/Makefile index 3060b9ebe..a677303f2 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ .PHONY: statusgo all test xgo clean help .PHONY: statusgo-android statusgo-ios +include ./static/tools/mk/lint.mk + GOBIN = build/bin GO ?= latest @@ -79,56 +81,6 @@ generate: ##@other Regenerate assets and other auto-generated stuff build/env.sh go generate ./static rm ./static/scripts/web3.js -lint-deps: - go get -u github.com/alecthomas/gometalinter - gometalinter --install - -lint-cur: - gometalinter --disable-all --enable=deadcode $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - -lint: ##@tests Run meta linter on code - @echo "Linter: go vet\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=vet $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: go vet --shadow\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=vetshadow $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: gofmt\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=gofmt $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: goimports\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=goimports $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: golint\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=golint $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: deadcode\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=deadcode $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: misspell\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=misspell $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: unparam\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --deadline 45s --enable=unparam $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: unused\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --deadline 45s --enable=unused $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: gocyclo\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=gocyclo --cyclo-over=20 $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: errcheck\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=errcheck $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: dupl\n--------------------" - @gometalinter $(LINT_EXCLUDE) --exclude='.*_test.go' --disable-all --enable=dupl --dupl-threshold=100 extkeys cmd/... geth/... | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: ineffassign\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=ineffassign $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: interfacer\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=interfacer $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: unconvert\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=unconvert $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: goconst\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=goconst $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: staticcheck\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --deadline 45s --enable=staticcheck $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: gas\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=gas $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: varcheck\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --deadline 60s --enable=varcheck $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: structcheck\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --enable=structcheck $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" - @echo "Linter: gosimple\n--------------------" - @gometalinter $(LINT_EXCLUDE) --disable-all --deadline 45s --enable=gosimple $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!" mock-install: ##@other Install mocking tools go get -u github.com/golang/mock/mockgen @@ -157,8 +109,4 @@ ci: mock-install mock test-coverage test-e2e ##@tests Run all tests in CI clean: ##@other Cleanup rm -fr build/bin/* - rm coverage.out coverage-all.out coverage.html - - -LINT_EXCLUDE := --exclude='.*_mock.go' --exclude='geth/jail/doc.go' -LINT_FOLDERS := extkeys cmd/... geth/... e2e/... \ No newline at end of file + rm coverage.out coverage-all.out coverage.html \ No newline at end of file diff --git a/static/config/linter_exclude_list.txt b/static/config/linter_exclude_list.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/static/tools/mk/lint.mk b/static/tools/mk/lint.mk new file mode 100644 index 000000000..4d2a3b41b --- /dev/null +++ b/static/tools/mk/lint.mk @@ -0,0 +1,70 @@ +LINT_EXCLUDE := --exclude='.*_mock.go' --exclude='geth/jail/doc.go' +LINT_FOLDERS := extkeys cmd/... geth/... e2e/... +LINT_FOLDERS_WITHOUT_TESTS := extkeys cmd/... geth/... + +lint-deps: + go get -u github.com/alecthomas/gometalinter + gometalinter --install + +lint: lint-vet lint-vetshadow lint-goimports lint-gofmt lint-deadcode lint-misspell lint-unparam lint-unused lint-gocyclo lint-errcheck lint-ineffassign lint-interfacer lint-unconvert lint-staticcheck lint-goconst lint-gas lint-varcheck lint-structcheck lint-gosimple + +lint-vet: + @echo "lint-vet" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=vet --deadline=45s $(LINT_FOLDERS) +lint-vetshadow: + @echo "lint-vetshadow" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=vetshadow --deadline=45s $(LINT_FOLDERS) +lint-goimports: + @echo "lint-goimports" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=goimports --deadline=45s $(LINT_FOLDERS) +lint-golint: + @echo "lint-golint" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=golint --deadline=45s $(LINT_FOLDERS) +lint-gofmt: + @echo "lint-gofmt" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=gofmt --deadline=45s $(LINT_FOLDERS) +lint-deadcode: + @echo "lint-deadcode" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=deadcode --deadline=45s $(LINT_FOLDERS) +lint-misspell: + @echo "lint-misspell" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=misspell --deadline=45s $(LINT_FOLDERS) +lint-unparam: + @echo "lint-unparam" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=unparam --deadline=45s $(LINT_FOLDERS) +lint-unused: + @echo "lint-unused" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=unused --deadline=45s $(LINT_FOLDERS) +lint-gocyclo: + @echo "lint-gocyclo" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=gocyclo --cyclo-over=20 --deadline=45s $(LINT_FOLDERS) +lint-errcheck: + @echo "lint-errcheck" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=errcheck --deadline=45s $(LINT_FOLDERS) +lint-ineffassign: + @echo "lint-ineffassign" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=ineffassign --deadline=45s $(LINT_FOLDERS) +lint-interfacer: + @echo "lint-interfacer" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=interfacer --deadline=45s $(LINT_FOLDERS) +lint-unconvert: + @echo "lint-unconvert" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=unconvert --deadline=45s $(LINT_FOLDERS) +lint-staticcheck: + @echo "lint-staticcheck" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=staticcheck --deadline=45s $(LINT_FOLDERS) +lint-goconst: + @echo "lint-goconst" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=goconst --deadline=45s $(LINT_FOLDERS) +lint-gas: + @echo "lint-gas" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=gas --deadline=45s $(LINT_FOLDERS) +lint-varcheck: + @echo "lint-varcheck" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=varcheck --deadline=45s $(LINT_FOLDERS) +lint-structcheck: + @echo "lint-structcheck" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=structcheck --deadline=45s $(LINT_FOLDERS) +lint-gosimple: + @echo "lint-gosimple" + @gometalinter $(LINT_EXCLUDE) --disable-all --enable=gosimple --deadline=45s $(LINT_FOLDERS) From 1de852134b1706cfa83e6753cf22df7e86a998b0 Mon Sep 17 00:00:00 2001 From: b00ris Date: Mon, 23 Oct 2017 13:41:41 +0300 Subject: [PATCH 2/2] fix linters warnings --- cmd/statusd/utils.go | 1 - e2e/suites.go | 6 ++---- e2e/transactions/transactions_test.go | 2 -- e2e/whisper/whisper_jail_test.go | 1 + 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/cmd/statusd/utils.go b/cmd/statusd/utils.go index b328cd3b3..b97a9641d 100644 --- a/cmd/statusd/utils.go +++ b/cmd/statusd/utils.go @@ -2,7 +2,6 @@ package main import "C" import ( - "context" "encoding/json" "io/ioutil" "math/big" diff --git a/e2e/suites.go b/e2e/suites.go index 17d9b1635..c5f2243c1 100644 --- a/e2e/suites.go +++ b/e2e/suites.go @@ -12,8 +12,7 @@ import ( // NodeManagerTestSuite defines a test suit with NodeManager. type NodeManagerTestSuite struct { suite.Suite - NodeManager common.NodeManager - nodeSyncCompleted bool + NodeManager common.NodeManager } // StartTestNode initiazes a NodeManager instances with configuration retrieved @@ -52,8 +51,7 @@ func (s *NodeManagerTestSuite) StopTestNode() { // and a few utility methods to start and stop node or get various services. type BackendTestSuite struct { suite.Suite - Backend *api.StatusBackend - nodeSyncCompleted bool + Backend *api.StatusBackend } // SetupTest initializes Backend. diff --git a/e2e/transactions/transactions_test.go b/e2e/transactions/transactions_test.go index 7c9db19b5..839844a75 100644 --- a/e2e/transactions/transactions_test.go +++ b/e2e/transactions/transactions_test.go @@ -9,8 +9,6 @@ import ( "testing" "time" - "context" - "github.com/ethereum/go-ethereum/accounts/keystore" gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" diff --git a/e2e/whisper/whisper_jail_test.go b/e2e/whisper/whisper_jail_test.go index b0150afc3..1db37c475 100644 --- a/e2e/whisper/whisper_jail_test.go +++ b/e2e/whisper/whisper_jail_test.go @@ -20,6 +20,7 @@ import ( ) const ( + //nolint: unused, varcheck whisperMessage1 = `test message 1 (K1 -> K2, signed+encrypted, from us)` whisperMessage2 = `test message 3 (K1 -> "", signed broadcast)` whisperMessage3 = `test message 4 ("" -> "", anon broadcast)`