Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Commit

Permalink
run linter in CI (#311)
Browse files Browse the repository at this point in the history
* linter: run it during CI

* Break import cycle in ethereum package

* Disable all linters and enable only unused
  • Loading branch information
zramsay authored and Adrian Brink committed Oct 22, 2017
1 parent bc4ab3e commit 8d12e40
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ test_race:
test_integrations:
@bash ./tests/test.sh

metalinter: ensure_tools
metalinter: ensure_tools install
@gometalinter --install
gometalinter --vendor --deadline=600s --enable-all --disable=lll ./...
gometalinter --vendor --disable-all --enable=unused ./...

draw_deps:
# requires brew install graphviz or apt-get install graphviz
Expand Down
5 changes: 3 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ test:
- go version
- echo "$REPO" && ls "$REPO"
- cd "$REPO" && make install
- cd "$REPO" && make metalinter
- cd "$REPO" && make test_coverage
#- cd "$REPO" && set -o pipefail && make test_integrations 2>&1 | tee test_integrations.log
# should be uncommented when CI is more robust
#- cd "$REPO" && make metalinter
# should be uncommented when CI is more robust
#- cd "$REPO" && make metalinter

post:
#- cd "$PROJECT_PATH" && mv test_integrations.log "${CIRCLE_ARTIFACTS}"
Expand Down
17 changes: 11 additions & 6 deletions cmd/ethermint/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
emtUtils "github.com/tendermint/ethermint/cmd/utils"
)

// nolint: vetshadow
// nolint: gocyclo
func initCmd(ctx *cli.Context) error {
genesisPath := ctx.Args().First()
genesis, err := emtUtils.ParseGenesisOrDefault(genesisPath)
Expand All @@ -35,7 +35,8 @@ func initCmd(ctx *cli.Context) error {
if canInvokeTendermintInit {
tendermintHome := filepath.Join(ethermintDataDir, "tendermint")
tendermintArgs := []string{"init", "--home", tendermintHome}
if _, err := invokeTendermint(tendermintArgs...); err != nil {
_, err = invokeTendermint(tendermintArgs...)
if err != nil {
ethUtils.Fatalf("tendermint init error: %v", err)
}
log.Info("successfully invoked `tendermint`", "args", tendermintArgs)
Expand Down Expand Up @@ -72,7 +73,9 @@ func initCmd(ctx *cli.Context) error {
if _, err := f.Write([]byte(content)); err != nil {
log.Error("write content %q err: %v", storeFileName, err)
}
f.Close()
if err := f.Close(); err != nil {
return err
}
}

return nil
Expand All @@ -96,20 +99,22 @@ var keystoreFilesMap = map[string]string{
`,
}

// nolint: unparam
func invokeTendermintNoTimeout(args ...string) ([]byte, error) {
return __invokeTendermint(context.TODO(), args...)
return _invokeTendermint(context.TODO(), args...)
}

func __invokeTendermint(ctx context.Context, args ...string) ([]byte, error) {
func _invokeTendermint(ctx context.Context, args ...string) ([]byte, error) {
log.Info("Invoking `tendermint`", "args", args)
cmd := exec.CommandContext(ctx, "tendermint", args...)
return cmd.CombinedOutput()
}

// nolint: unparam
func invokeTendermint(args ...string) ([]byte, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
return __invokeTendermint(ctx, args...)
return _invokeTendermint(ctx, args...)
}

func canInvokeTendermint(ctx *cli.Context) bool {
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var (
Value: GenesisTargetGasLimit.Uint64(),
}

// WithTendermint flag asks to start Tendermint
// WithTendermintFlag asks to start Tendermint
// `tendermint init` and `tendermint node` when `ethermint init`
// and `ethermint` are invoked respectively.
WithTendermintFlag = cli.BoolFlag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/utils/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (
"github.com/ethereum/go-ethereum/core"
)

var defaultGenesis *core.Genesis = func() *core.Genesis {
var defaultGenesis = func() *core.Genesis {
g := new(core.Genesis)
if err := json.Unmarshal(defaultGenesisBlob, g); err != nil {
log.Fatalf("parsing defaultGenesis: %v", err)
}
return g
}()

func bigString(s string) *big.Int {
func bigString(s string) *big.Int { // nolint: unparam
b, _ := big.NewInt(0).SetString(s, 10)
return b
}
Expand Down
10 changes: 4 additions & 6 deletions ethereum/node_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ethereum_test
package ethereum

import (
"flag"
Expand All @@ -10,8 +10,6 @@ import (
"github.com/stretchr/testify/assert"

"github.com/ethereum/go-ethereum/node"

"github.com/tendermint/ethermint/ethereum"
)

var dummyApp = &cli.App{
Expand All @@ -28,7 +26,7 @@ func TestNewNodeConfig(t *testing.T) {
assert.Nil(t, err, "expecting no panics")
}()

ncfg := ethereum.NewNodeConfig(dummyContext)
ncfg := NewNodeConfig(dummyContext)
assert.NotNil(t, ncfg, "expecting a non-nil config")
}

Expand All @@ -38,15 +36,15 @@ func TestNewEthConfig(t *testing.T) {
assert.Nil(t, err, "expecting no panics")
}()

ecfg := ethereum.NewEthConfig(dummyContext, dummyNode)
ecfg := NewEthConfig(dummyContext, dummyNode)
assert.NotNil(t, ecfg, "expecting a non-nil config")
}

func TestEnsureDisabledEthereumP2PStack(t *testing.T) {
cfg := new(node.Config)
*cfg = node.DefaultConfig
cfg.P2P.ListenAddr = ":34555"
node, err := ethereum.New(cfg)
node, err := New(cfg)
if err != nil {
t.Fatalf("cannot initialise new node from config: %v", err)
}
Expand Down

0 comments on commit 8d12e40

Please sign in to comment.