Skip to content

Commit

Permalink
ci: Fix linter complaint (backport tendermint#9645) (tendermint#9647)
Browse files Browse the repository at this point in the history
* ci: Fix linter complaint (tendermint#9645)

Fixes a very silly linter complaint that makes absolutely no sense and is blocking the merging of several PRs.

---

#### PR checklist

- [x] Tests written/updated, or no tests needed
- [x] `CHANGELOG_PENDING.md` updated, or no changelog entry needed
- [x] Updated relevant documentation (`docs/`) and code comments, or no
      documentation updates needed

(cherry picked from commit 83b7f4a)

# Conflicts:
#	.github/workflows/lint.yml
#	.golangci.yml
#	cmd/tendermint/commands/debug/util.go

* Resolve conflicts

Signed-off-by: Thane Thomson <[email protected]>

* ci: Sync golangci-lint config with main

Minus the spelling configuration that restricts spelling to US English
only.

Signed-off-by: Thane Thomson <[email protected]>

* make format

Signed-off-by: Thane Thomson <[email protected]>

* Remove usage of deprecated io/ioutil package

Signed-off-by: Thane Thomson <[email protected]>

* Remove unused mockBlockStore

Signed-off-by: Thane Thomson <[email protected]>

* blockchain/v2: Remove unused method

Signed-off-by: Thane Thomson <[email protected]>

* Bulk fix lints

Signed-off-by: Thane Thomson <[email protected]>

* lint: Ignore auto-generated query PEG

Signed-off-by: Thane Thomson <[email protected]>

Signed-off-by: Thane Thomson <[email protected]>
Co-authored-by: Thane Thomson <[email protected]>
  • Loading branch information
mergify[bot] and thanethomson authored Oct 29, 2022
1 parent a6dd0d2 commit e914fe4
Show file tree
Hide file tree
Showing 93 changed files with 425 additions and 476 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ jobs:
go.sum
- uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.47.3
version: v1.50.1
args: --timeout 10m
github-token: ${{ secrets.github_token }}
if: env.GIT_DIFF
42 changes: 8 additions & 34 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,45 @@ linters:
enable:
- asciicheck
- bodyclose
# - deadcode
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
# - funlen
# - gochecknoglobals
# - gochecknoinits
# - gocognit
- goconst
# - gocritic
# - gocyclo
# - godox
- gofmt
- goimports
- revive
- gosec
- gosimple
- govet
- ineffassign
# - interfacer
- lll
# - maligned
# - misspell
- misspell
- nakedret
# - nolintlint
- nolintlint
- prealloc
- staticcheck
# - structcheck // to be fixed by golangci-lint
- stylecheck
# - typecheck
- typecheck
- unconvert
# - unparam
# - unused
- varcheck
# - whitespace
# - wsl
disable:
- unused
- deadcode
- nolintlint

issues:
exclude-rules:
- path: _test\.go
linters:
- gosec
- linters:
- lll
source: "https://"
max-same-issues: 50

linters-settings:
dogsled:
max-blank-identifiers: 3
golint:
min-confidence: 0
maligned:
suggest-new: true
# govet:
# check-shadowing: true
revive:
min-confidence: 0
misspell:
locale: US
ignore-words:
- behaviour


run:
skip-files:
- libs/pubsub/query/query.peg.go
14 changes: 6 additions & 8 deletions abci/example/kvstore/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package kvstore

import (
"fmt"
"io/ioutil"
"os"
"sort"
"testing"

Expand Down Expand Up @@ -71,7 +71,7 @@ func TestKVStoreKV(t *testing.T) {
}

func TestPersistentKVStoreKV(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil {
t.Fatal(err)
}
Expand All @@ -87,7 +87,7 @@ func TestPersistentKVStoreKV(t *testing.T) {
}

func TestPersistentKVStoreInfo(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil {
t.Fatal(err)
}
Expand All @@ -114,12 +114,11 @@ func TestPersistentKVStoreInfo(t *testing.T) {
if resInfo.LastBlockHeight != height {
t.Fatalf("expected height of %d, got %d", height, resInfo.LastBlockHeight)
}

}

// add a validator, remove a validator, update a validator
func TestValUpdates(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -181,15 +180,15 @@ func TestValUpdates(t *testing.T) {
vals1 = append([]types.ValidatorUpdate{v1}, vals1[1:]...)
vals2 = kvstore.Validators()
valsEqual(t, vals1, vals2)

}

func makeApplyBlock(
t *testing.T,
kvstore types.Application,
heightInt int,
diff []types.ValidatorUpdate,
txs ...[]byte) {
txs ...[]byte,
) {
// make and apply block
height := int64(heightInt)
hash := []byte("foo")
Expand All @@ -207,7 +206,6 @@ func makeApplyBlock(
kvstore.Commit()

valsEqual(t, diff, resEndBlock.ValidatorUpdates)

}

// order doesn't matter
Expand Down
32 changes: 8 additions & 24 deletions blockchain/v2/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,7 @@ func (mp mockPeer) Get(string) interface{} { return struct{}{} }
func (mp mockPeer) SetRemovalFailed() {}
func (mp mockPeer) GetRemovalFailed() bool { return false }

type mockBlockStore struct {
blocks map[int64]*types.Block
}

func (ml *mockBlockStore) Height() int64 {
return int64(len(ml.blocks))
}

func (ml *mockBlockStore) LoadBlock(height int64) *types.Block {
return ml.blocks[height]
}

func (ml *mockBlockStore) SaveBlock(block *types.Block, part *types.PartSet, commit *types.Commit) {
ml.blocks[block.Height] = block
}

type mockBlockApplier struct {
}
type mockBlockApplier struct{}

// XXX: Add whitelist/blacklist?
func (mba *mockBlockApplier) ApplyBlock(
Expand Down Expand Up @@ -351,9 +334,7 @@ func newTestReactor(p testReactorParams) *BlockchainReactor {
// }

func TestReactorHelperMode(t *testing.T) {
var (
channelID = byte(0x40)
)
channelID := byte(0x40)

config := cfg.ResetTestRoot("blockchain_reactor_v2_test")
defer os.RemoveAll(config.RootDir)
Expand Down Expand Up @@ -466,7 +447,8 @@ type testApp struct {
}

func randGenesisDoc(chainID string, numValidators int, randPower bool, minPower int64) (
*types.GenesisDoc, []types.PrivValidator) {
*types.GenesisDoc, []types.PrivValidator,
) {
validators := make([]types.GenesisValidator, numValidators)
privValidators := make([]types.PrivValidator, numValidators)
for i := 0; i < numValidators; i++ {
Expand All @@ -491,7 +473,8 @@ func randGenesisDoc(chainID string, numValidators int, randPower bool, minPower
func newReactorStore(
genDoc *types.GenesisDoc,
privVals []types.PrivValidator,
maxBlockHeight int64) (*store.BlockStore, sm.State, *sm.BlockExecutor) {
maxBlockHeight int64,
) (*store.BlockStore, sm.State, *sm.BlockExecutor) {
if len(privVals) != 1 {
panic("only support one validator")
}
Expand All @@ -515,7 +498,8 @@ func newReactorStore(

db := dbm.NewMemDB()
stateStore = sm.NewStore(db, sm.StoreOptions{
DiscardABCIResponses: false},
DiscardABCIResponses: false,
},
)
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(),
mock.Mempool{}, sm.EmptyEvidencePool{})
Expand Down
4 changes: 0 additions & 4 deletions blockchain/v2/routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ func (rt *Routine) setLogger(logger log.Logger) {
rt.logger = logger
}

func (rt *Routine) setMetrics(metrics *Metrics) {
rt.metrics = metrics
}

func (rt *Routine) start() {
rt.logger.Info("routine start", "msg", log.NewLazySprintf("%s: run", rt.name))
running := atomic.CompareAndSwapUint32(rt.running, uint32(0), uint32(1))
Expand Down
3 changes: 1 addition & 2 deletions cmd/tendermint/commands/debug/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package debug
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -82,7 +81,7 @@ func dumpCmdHandler(_ *cobra.Command, args []string) error {
func dumpDebugData(outDir string, conf *cfg.Config, rpc *rpchttp.HTTP) {
start := time.Now().UTC()

tmpDir, err := ioutil.TempDir(outDir, "tendermint_debug_tmp")
tmpDir, err := os.MkdirTemp(outDir, "tendermint_debug_tmp")
if err != nil {
logger.Error("failed to create temporary directory", "dir", tmpDir, "error", err)
return
Expand Down
4 changes: 1 addition & 3 deletions cmd/tendermint/commands/debug/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -68,7 +67,6 @@ func zipDir(src, dest string) error {
_, err = io.Copy(headerWriter, file)
return err
})

}

// copyFile copies a file from src to dest and returns an error upon failure. The
Expand Down Expand Up @@ -111,5 +109,5 @@ func writeStateJSONToFile(state interface{}, dir, filename string) error {
return fmt.Errorf("failed to encode state dump: %w", err)
}

return ioutil.WriteFile(path.Join(dir, filename), stateJSON, os.ModePerm)
return os.WriteFile(path.Join(dir, filename), stateJSON, os.ModePerm)
}
3 changes: 1 addition & 2 deletions cmd/tendermint/commands/debug/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package debug
import (
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -56,7 +55,7 @@ func killCmdHandler(cmd *cobra.Command, args []string) error {

// Create a temporary directory which will contain all the state dumps and
// relevant files and directories that will be compressed into a file.
tmpDir, err := ioutil.TempDir(os.TempDir(), "tendermint_debug_tmp")
tmpDir, err := os.MkdirTemp(os.TempDir(), "tendermint_debug_tmp")
if err != nil {
return fmt.Errorf("failed to create temporary directory: %w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/tendermint/commands/debug/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package debug
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -67,16 +67,17 @@ func copyConfig(home, dir string) error {
func dumpProfile(dir, addr, profile string, debug int) error {
endpoint := fmt.Sprintf("%s/debug/pprof/%s?debug=%d", addr, profile, debug)

resp, err := http.Get(endpoint) //nolint: gosec
//nolint:gosec,nolintlint
resp, err := http.Get(endpoint)
if err != nil {
return fmt.Errorf("failed to query for %s profile: %w", profile, err)
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read %s profile response body: %w", profile, err)
}

return ioutil.WriteFile(path.Join(dir, fmt.Sprintf("%s.out", profile)), body, os.ModePerm)
return os.WriteFile(path.Join(dir, fmt.Sprintf("%s.out", profile)), body, os.ModePerm)
}
3 changes: 2 additions & 1 deletion cmd/tendermint/commands/reindex_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

dbm "github.com/tendermint/tm-db"

abcitypes "github.com/tendermint/tendermint/abci/types"
tmcfg "github.com/tendermint/tendermint/config"
prototmstate "github.com/tendermint/tendermint/proto/tendermint/state"
blockmocks "github.com/tendermint/tendermint/state/indexer/mocks"
"github.com/tendermint/tendermint/state/mocks"
txmocks "github.com/tendermint/tendermint/state/txindex/mocks"
"github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
)

const (
Expand Down
11 changes: 3 additions & 8 deletions cmd/tendermint/commands/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package commands

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand All @@ -18,9 +17,7 @@ import (
tmos "github.com/tendermint/tendermint/libs/os"
)

var (
defaultRoot = os.ExpandEnv("$HOME/.some/test/dir")
)
var defaultRoot = os.ExpandEnv("$HOME/.some/test/dir")

// clearConfig clears env vars, the given root dir, and resets viper.
func clearConfig(dir string) {
Expand Down Expand Up @@ -88,7 +85,6 @@ func TestRootHome(t *testing.T) {
}

func TestRootFlagsEnv(t *testing.T) {

// defaults
defaults := cfg.DefaultConfig()
defaultLogLvl := defaults.LogLevel
Expand Down Expand Up @@ -116,7 +112,6 @@ func TestRootFlagsEnv(t *testing.T) {
}

func TestRootConfig(t *testing.T) {

// write non-default config
nonDefaultLogLvl := "abc:debug"
cvals := map[string]string{
Expand All @@ -140,7 +135,7 @@ func TestRootConfig(t *testing.T) {

// XXX: path must match cfg.defaultConfigPath
configFilePath := filepath.Join(defaultRoot, "config")
err := tmos.EnsureDir(configFilePath, 0700)
err := tmos.EnsureDir(configFilePath, 0o700)
require.Nil(t, err)

// write the non-defaults to a different path
Expand Down Expand Up @@ -168,5 +163,5 @@ func WriteConfigVals(dir string, vals map[string]string) error {
data += fmt.Sprintf("%s = \"%s\"\n", k, v)
}
cfile := filepath.Join(dir, "config.toml")
return ioutil.WriteFile(cfile, []byte(data), 0600)
return os.WriteFile(cfile, []byte(data), 0o600)
}
Loading

0 comments on commit e914fe4

Please sign in to comment.