Feature/integrate linters into ci#387 (#427)

Solves #387 linters was integrated into ci
Added inergration linters to CI
Important changes:
- new linter warnings was fixed
- extracted linters targets into separated mk file
This commit is contained in:
Ivan Tomilov 2017-10-24 19:36:52 +03:00 committed by GitHub
commit f80827dc1f
7 changed files with 83 additions and 63 deletions

View File

@ -9,10 +9,14 @@ dist: trusty
install: install:
- go get golang.org/x/tools/cmd/cover - go get golang.org/x/tools/cmd/cover
- make lint-deps
script: jobs:
- make ci include:
- stage: lint
script: make lint
- stage: ci
script: make ci
cache: cache:
directories: directories:
- .ethereumtest - .ethereumtest

View File

@ -1,6 +1,8 @@
.PHONY: statusgo all test xgo clean help .PHONY: statusgo all test xgo clean help
.PHONY: statusgo-android statusgo-ios .PHONY: statusgo-android statusgo-ios
include ./static/tools/mk/lint.mk
GOBIN = build/bin GOBIN = build/bin
GO ?= latest GO ?= latest
@ -79,56 +81,6 @@ generate: ##@other Regenerate assets and other auto-generated stuff
build/env.sh go generate ./static build/env.sh go generate ./static
rm ./static/scripts/web3.js 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 mock-install: ##@other Install mocking tools
go get -u github.com/golang/mock/mockgen go get -u github.com/golang/mock/mockgen
@ -158,8 +110,4 @@ ci: mock-install mock test-coverage test-e2e ##@tests Run all tests in CI
clean: ##@other Cleanup clean: ##@other Cleanup
rm -fr build/bin/* rm -fr build/bin/*
rm coverage.out coverage-all.out coverage.html rm coverage.out coverage-all.out coverage.html
LINT_EXCLUDE := --exclude='.*_mock.go' --exclude='geth/jail/doc.go'
LINT_FOLDERS := extkeys cmd/... geth/... e2e/...

View File

@ -2,7 +2,6 @@ package main
import "C" import "C"
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"

View File

@ -12,8 +12,7 @@ import (
// NodeManagerTestSuite defines a test suit with NodeManager. // NodeManagerTestSuite defines a test suit with NodeManager.
type NodeManagerTestSuite struct { type NodeManagerTestSuite struct {
suite.Suite suite.Suite
NodeManager common.NodeManager NodeManager common.NodeManager
nodeSyncCompleted bool
} }
// StartTestNode initiazes a NodeManager instances with configuration retrieved // 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. // and a few utility methods to start and stop node or get various services.
type BackendTestSuite struct { type BackendTestSuite struct {
suite.Suite suite.Suite
Backend *api.StatusBackend Backend *api.StatusBackend
nodeSyncCompleted bool
} }
// SetupTest initializes Backend. // SetupTest initializes Backend.

View File

@ -20,6 +20,7 @@ import (
) )
const ( const (
//nolint: unused, varcheck
whisperMessage1 = `test message 1 (K1 -> K2, signed+encrypted, from us)` whisperMessage1 = `test message 1 (K1 -> K2, signed+encrypted, from us)`
whisperMessage2 = `test message 3 (K1 -> "", signed broadcast)` whisperMessage2 = `test message 3 (K1 -> "", signed broadcast)`
whisperMessage3 = `test message 4 ("" -> "", anon broadcast)` whisperMessage3 = `test message 4 ("" -> "", anon broadcast)`

70
static/tools/mk/lint.mk Normal file
View File

@ -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)