Skip to content

Commit

Permalink
gometalinter -> golangci-lint migration (cosmos#3933)
Browse files Browse the repository at this point in the history
{,scripts/}Makefile:
- Remove gometalinter, install golangci-lint.
- Remove distinction between tools and devtools.
  Just tools is enough.
- test_lint -> lint
  Migrating away from underscore separated names.
- Remove unnecessary targets.
- Drop tendermint/lint. Incompatbile with golangci-lint
  and no longer necessary anyway.
- Fix misleading message in go-mod-cache.
- New ci-target to avoid download tools twice.
- Run tests with -mod=readonly.

Port tools/gometalinter.json to .golangci.yml
Update CircleCI config accordingly.

Closes: cosmos#3896
  • Loading branch information
alessio authored Mar 19, 2019
1 parent faefc80 commit cdf2b7a
Show file tree
Hide file tree
Showing 24 changed files with 213 additions and 131 deletions.
44 changes: 36 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
- run: mkdir -p /tmp/workspace/bin
- run: mkdir -p /tmp/workspace/profiles
- checkout
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: tools
command: |
Expand All @@ -65,6 +68,10 @@ jobs:
export PATH="$GOBIN:$PATH"
make go-mod-cache
make install
- save_cache:
key: go-mod-v1-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- persist_to_workspace:
root: /tmp/workspace
paths:
Expand All @@ -79,17 +86,14 @@ jobs:
at: /tmp/workspace
- checkout
- *dependencies
- run:
name: Get metalinter
command: |
export PATH="$GOBIN:$PATH"
make devtools-clean
make devtools
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Lint source
command: |
export PATH="$GOBIN:$PATH"
make test_lint
make ci-lint
integration_tests:
<<: *linux_defaults
Expand All @@ -99,6 +103,9 @@ jobs:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test cli
command: |
Expand All @@ -113,6 +120,9 @@ jobs:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test individual module simulations
command: |
Expand All @@ -127,6 +137,9 @@ jobs:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test full Gaia simulation
command: |
Expand All @@ -141,6 +154,9 @@ jobs:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test Gaia import/export simulation
command: |
Expand All @@ -155,6 +171,9 @@ jobs:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test Gaia import/export simulation
command: |
Expand All @@ -169,6 +188,9 @@ jobs:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test multi-seed Gaia simulation long
command: |
Expand All @@ -184,6 +206,9 @@ jobs:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test multi-seed Gaia simulation short
command: |
Expand All @@ -200,6 +225,9 @@ jobs:
- checkout
- *dependencies
- run: mkdir -p /tmp/logs
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Run tests
command: |
Expand All @@ -208,7 +236,7 @@ jobs:
export GO111MODULE=on
for pkg in $(go list ./... | grep -v github.com/cosmos/cosmos-sdk/cmd/gaia/cli_test | grep -v '/simulation' | circleci tests split --split-by=timings); do
id=$(echo "$pkg" | sed 's|[/.]|_|g')
go test -timeout 8m -race -coverprofile=/tmp/workspace/profiles/$id.out -covermode=atomic -tags='ledger test_ledger_mock' "$pkg" | tee "/tmp/logs/$id-$RANDOM.log"
go test -mod=readonly -timeout 8m -race -coverprofile=/tmp/workspace/profiles/$id.out -covermode=atomic -tags='ledger test_ledger_mock' "$pkg" | tee "/tmp/logs/$id-$RANDOM.log"
done
- persist_to_workspace:
root: /tmp/workspace
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ examples/build/*
docs/_build
docs/tutorial
dist
devtools-stamp
tools-stamp

# Data - ideally these don't exist
baseapp/data/*
Expand Down
17 changes: 17 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
linters:
disable-all: true
enable:
- errcheck
- golint
- ineffassign
- unconvert
- misspell
linters-settings:
gocyclo:
min-complexity: 11
errcheck:
ignore: fmt:.*,io/ioutil:^Read.*,github.com/spf13/cobra:MarkFlagRequired,github.com/spf13/viper:BindPFlag
golint:
min-confidence: 1.1
run:
tests: false
1 change: 1 addition & 0 deletions .pending/improvements/sdk/Fixed-various-linter
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed various linters warnings in the context of the gometalinter -> golangci-lint migration #3896.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ only pull requests targeted directly against master.
### Development Procedure:
- the latest state of development is on `develop`
- `develop` must never fail `make test` or `make test_cli`
- `develop` should not fail `make test_lint`
- `develop` should not fail `make lint`
- no --force onto `develop` (except when reverting a broken commit, which should seldom happen)
- create a development branch either on github.com/cosmos/cosmos-sdk, or your fork (using `git remote add origin`)
- before submitting a pull request, begin `git rebase` on top of `develop`
Expand Down
75 changes: 24 additions & 51 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
CAT := $(if $(filter $(OS),Windows_NT),type,cat)
LEDGER_ENABLED ?= true
GOTOOLS = \
github.com/alecthomas/gometalinter \
github.com/rakyll/statik
GOBIN ?= $(GOPATH)/bin
GOSUM := $(shell which gosum)

Expand Down Expand Up @@ -62,15 +59,15 @@ ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'

all: devtools install test_lint test
all: tools install lint test

# The below include contains the tools target.
include scripts/Makefile

########################################
### CI

ci: devtools install test_cover test_lint test
ci: tools install test_cover lint test

########################################
### Build/Install
Expand Down Expand Up @@ -108,37 +105,12 @@ dist:
########################################
### Tools & dependencies

check_tools:
@# https://stackoverflow.com/a/25668869
@echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
$(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"

update_tools:
@echo "--> Updating tools to correct version"
$(MAKE) --always-make tools

update_dev_tools:
@echo "--> Downloading linters (this may take awhile)"
$(GOPATH)/src/github.com/alecthomas/gometalinter/scripts/install.sh -b $(GOBIN)
go get -u github.com/tendermint/lint/golint

devtools: devtools-stamp
devtools-stamp: tools
@echo "--> Downloading linters (this may take awhile)"
$(GOPATH)/src/github.com/alecthomas/gometalinter/scripts/install.sh -b $(GOBIN)
go get github.com/tendermint/lint/golint
go install -mod=readonly ./cmd/sdkch
touch $@

devtools-clean: tools-clean
rm -f devtools-stamp

go-mod-cache: go.sum
@echo "--> Download go modules to local cache"
@go mod download

go.sum: tools go.mod
@echo "--> Generating vendor directory via go mod vendor"
@echo "--> Ensure dependencies have not been modified"
@go mod verify

draw_deps: tools
Expand All @@ -147,7 +119,7 @@ draw_deps: tools
@goviz -i github.com/cosmos/cosmos-sdk/cmd/gaia/cmd/gaiad -d 2 | dot -Tpng -o dependency-graph.png

clean:
rm -f devtools-stamp snapcraft-local.yaml
rm -f snapcraft-local.yaml

distclean: clean
rm -rf vendor/
Expand All @@ -166,33 +138,33 @@ godocs:
test: test_unit

test_cli: build
@go test -p 4 `go list ./cmd/gaia/cli_test/...` -tags=cli_test
@go test -mod=readonly -p 4 `go list ./cmd/gaia/cli_test/...` -tags=cli_test

test_ledger:
# First test with mock
@go test `go list github.com/cosmos/cosmos-sdk/crypto` -tags='cgo ledger test_ledger_mock'
@go test -mod=readonly `go list github.com/cosmos/cosmos-sdk/crypto` -tags='cgo ledger test_ledger_mock'
# Now test with a real device
@go test -v `go list github.com/cosmos/cosmos-sdk/crypto` -tags='cgo ledger'
@go test -mod=readonly -v `go list github.com/cosmos/cosmos-sdk/crypto` -tags='cgo ledger'

test_unit:
@VERSION=$(VERSION) go test $(PACKAGES_NOSIMULATION) -tags='ledger test_ledger_mock'
@VERSION=$(VERSION) go test -mod=readonly $(PACKAGES_NOSIMULATION) -tags='ledger test_ledger_mock'

test_race:
@VERSION=$(VERSION) go test -race $(PACKAGES_NOSIMULATION)
@VERSION=$(VERSION) go test -mod=readonly -race $(PACKAGES_NOSIMULATION)

test_sim_gaia_nondeterminism:
@echo "Running nondeterminism test..."
@go test ./cmd/gaia/app -run TestAppStateDeterminism -SimulationEnabled=true -v -timeout 10m
@go test -mod=readonly ./cmd/gaia/app -run TestAppStateDeterminism -SimulationEnabled=true -v -timeout 10m

test_sim_gaia_custom_genesis_fast:
@echo "Running custom genesis simulation..."
@echo "By default, ${HOME}/.gaiad/config/genesis.json will be used."
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationGenesis=${HOME}/.gaiad/config/genesis.json \
@go test -mod=readonly ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationGenesis=${HOME}/.gaiad/config/genesis.json \
-SimulationEnabled=true -SimulationNumBlocks=100 -SimulationBlockSize=200 -SimulationCommit=true -SimulationSeed=99 -SimulationPeriod=5 -v -timeout 24h

test_sim_gaia_fast:
@echo "Running quick Gaia simulation. This may take several minutes..."
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=100 -SimulationBlockSize=200 -SimulationCommit=true -SimulationSeed=99 -SimulationPeriod=5 -v -timeout 24h
@go test -mod=readonly ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=100 -SimulationBlockSize=200 -SimulationCommit=true -SimulationSeed=99 -SimulationPeriod=5 -v -timeout 24h

test_sim_gaia_import_export:
@echo "Running Gaia import/export simulation. This may take several minutes..."
Expand All @@ -216,30 +188,31 @@ SIM_BLOCK_SIZE ?= 200
SIM_COMMIT ?= true
test_sim_gaia_benchmark:
@echo "Running Gaia benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!"
@go test -benchmem -run=^$$ github.com/cosmos/cosmos-sdk/cmd/gaia/app -bench ^BenchmarkFullGaiaSimulation$$ \
@go test -mod=readonly -benchmem -run=^$$ github.com/cosmos/cosmos-sdk/cmd/gaia/app -bench ^BenchmarkFullGaiaSimulation$$ \
-SimulationEnabled=true -SimulationNumBlocks=$(SIM_NUM_BLOCKS) -SimulationBlockSize=$(SIM_BLOCK_SIZE) -SimulationCommit=$(SIM_COMMIT) -timeout 24h

test_sim_gaia_profile:
@echo "Running Gaia benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!"
@go test -benchmem -run=^$$ github.com/cosmos/cosmos-sdk/cmd/gaia/app -bench ^BenchmarkFullGaiaSimulation$$ \
@go test -mod=readonly -benchmem -run=^$$ github.com/cosmos/cosmos-sdk/cmd/gaia/app -bench ^BenchmarkFullGaiaSimulation$$ \
-SimulationEnabled=true -SimulationNumBlocks=$(SIM_NUM_BLOCKS) -SimulationBlockSize=$(SIM_BLOCK_SIZE) -SimulationCommit=$(SIM_COMMIT) -timeout 24h -cpuprofile cpu.out -memprofile mem.out

test_cover:
@export VERSION=$(VERSION); bash -x tests/test_cover.sh

test_lint:
gometalinter --config=tools/gometalinter.json ./...
!(gometalinter --exclude /usr/lib/go/src/ --exclude client/lcd/statik/statik.go --exclude 'vendor/*' --disable-all --enable='errcheck' --vendor ./... | grep -v "client/")
lint: tools ci-lint
ci-lint:
golangci-lint run
go vet -composites=false -tests=false ./...
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
go mod verify

format:
format: tools
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/cosmos/cosmos-sdk

benchmark:
@go test -bench=. $(PACKAGES_NOSIMULATION)
@go test -mod=readonly -bench=. $(PACKAGES_NOSIMULATION)


########################################
Expand Down Expand Up @@ -292,10 +265,10 @@ snapcraft-local.yaml: snapcraft-local.yaml.in
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: build install install_debug dist clean distclean \
check_tools check_dev_tools get_vendor_deps draw_deps test test_cli test_unit \
test_cover test_lint benchmark devdoc_init devdoc devdoc_save devdoc_update \
draw_deps test test_cli test_unit \
test_cover lint benchmark devdoc_init devdoc devdoc_save devdoc_update \
build-linux build-docker-gaiadnode localnet-start localnet-stop \
format check-ledger test_sim_gaia_nondeterminism test_sim_modules test_sim_gaia_fast \
test_sim_gaia_custom_genesis_fast test_sim_gaia_custom_genesis_multi_seed \
test_sim_gaia_multi_seed test_sim_gaia_import_export update_tools update_dev_tools \
devtools-clean go-mod-cache
test_sim_gaia_multi_seed test_sim_gaia_import_export \
go-mod-cache
24 changes: 24 additions & 0 deletions client/keys/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ type AddNewKey struct {
Index int `json:"index,string,omitempty"`
}

// NewAddNewKey constructs a new AddNewKey request structure.
func NewAddNewKey(name, password, mnemonic string, account, index int) AddNewKey {
return AddNewKey{
Name: name,
Password: password,
Mnemonic: mnemonic,
Account: account,
Index: index,
}
}

// RecoverKeyBody recovers a key
type RecoverKey struct {
Password string `json:"password"`
Expand All @@ -19,13 +30,26 @@ type RecoverKey struct {
Index int `json:"index,string,omitempty"`
}

// NewRecoverKey constructs a new RecoverKey request structure.
func NewRecoverKey(password, mnemonic string, account, index int) RecoverKey {
return RecoverKey{Password: password, Mnemonic: mnemonic, Account: account, Index: index}
}

// UpdateKeyReq requests updating a key
type UpdateKeyReq struct {
OldPassword string `json:"old_password"`
NewPassword string `json:"new_password"`
}

// NewUpdateKeyReq constructs a new UpdateKeyReq structure.
func NewUpdateKeyReq(old, new string) UpdateKeyReq {
return UpdateKeyReq{OldPassword: old, NewPassword: new}
}

// DeleteKeyReq requests deleting a key
type DeleteKeyReq struct {
Password string `json:"password"`
}

// NewDeleteKeyReq constructs a new DeleteKeyReq structure.
func NewDeleteKeyReq(password string) DeleteKeyReq { return DeleteKeyReq{Password: password} }
4 changes: 3 additions & 1 deletion client/lcd/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ func fingerprintForCertificate(certBytes []byte) (string, error) {
return "", err
}
h := sha256.New()
h.Write(cert.Raw)
if _, err := h.Write(cert.Raw); err != nil {
return "", err
}
fingerprintBytes := h.Sum(nil)
var buf bytes.Buffer
for i, b := range fingerprintBytes {
Expand Down
Loading

0 comments on commit cdf2b7a

Please sign in to comment.