Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(linting): lint all files based on latest setting #1171

Merged
merged 19 commits into from
Nov 8, 2023
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- 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.51
version: v1.55
args: --timeout 10m
github-token: ${{ secrets.GITHUB_TOKEN }}
if: env.GIT_DIFF
142 changes: 121 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
run:
tests: false
# # timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m
tests: true
timeout: 15m
sort-results: true
allow-parallel-runners: true
exclude-dir: testutil/testdata
skip-files:
- server/grpc/gogoreflection/fix_registration.go
- "fix_registration.go"
- ".*\\.pb\\.go$"
- ".*\\.pb\\.gw\\.go$"
- ".*\\.pulsar\\.go$"
- crypto/keys/secp256k1/internal/*
build-tags:
- ledger
- goleveldb
- test_ledger_mock

linters:
disable-all: false
disable-all: true
enable:
- gofmt
- errcheck
- dogsled
- exportloopref
- goconst
- goimports
- golint
- gocritic
- gci
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- scopelint
- nolintlint
- staticcheck
- revive
- stylecheck
- typecheck
- thelper
- unconvert
- unused
- unparam
- misspell
disable:
- gocritic
- maligned
- errcheck
- interfacer
- wsl
- nolintlint

issues:
exclude-rules:
Expand All @@ -52,16 +60,108 @@ issues:
- text: "SA1019: collection."
linters:
- staticcheck
- path: "legacy"
text: "SA1019:"
linters:
- staticcheck
- text: "SA1019: codec.NewAminoCodec is deprecated" # TODO remove once migration path is set out
linters:
- staticcheck
- text: "SA1019: legacybech32.MustMarshalPubKey" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: legacybech32.MarshalPubKey" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: legacybech32.UnmarshalPubKey" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: params.SendEnabled is deprecated" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: \"github.com/golang/protobuf/proto\" is deprecated" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: vote.Option is deprecated" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: types.QueryNextAccountNumberRequest is deprecated" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "leading space"
linters:
- nolintlint
- path: _test\.go
linters:
- goconst
max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
gci:
custom-order: true
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/Finschia/ostracon)
- prefix(github.com/Finschia/finschia-sdk)
revive:
rules:
- name: redefines-builtin-id
disabled: true

gosec:
includes:
# - G101 # Look for hard coded credentials
- G102 # Bind to all interfaces
- G103 # Audit the use of unsafe block
- G104 # Audit errors not checked
- G106 # Audit the use of ssh.InsecureIgnoreHostKey
- G107 # Url provided to HTTP request as taint input
- G108 # Profiling endpoint automatically exposed on /debug/pprof
- G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32
- G110 # Potential DoS vulnerability via decompression bomb
- G111 # Potential directory traversal
- G112 # Potential slowloris attack
- G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772)
- G114 # Use of net/http serve function that has no support for setting timeouts
- G201 # SQL query construction using format string
- G202 # SQL query construction using string concatenation
- G203 # Use of unescaped data in HTML templates
- G204 # Audit use of command execution
- G301 # Poor file permissions used when creating a directory
- G302 # Poor file permissions used with chmod
- G303 # Creating tempfile using a predictable path
- G304 # File path provided as taint input
- G305 # File traversal when extracting zip/tar archive
- G306 # Poor file permissions used when writing to a new file
- G307 # Deferring a method which returns an error
- G401 # Detect the usage of DES, RC4, MD5 or SHA1
- G402 # Look for bad TLS connection settings
- G403 # Ensure minimum RSA key length of 2048 bits
- G404 # Insecure random number source (rand)
- G501 # Import blocklist: crypto/md5
- G502 # Import blocklist: crypto/des
- G503 # Import blocklist: crypto/rc4
- G504 # Import blocklist: net/http/cgi
- G505 # Import blocklist: crypto/sha1
- G601 # Implicit memory aliasing of items from a range statement
misspell:
locale: US
gofumpt:
extra-rules: true
dogsled:
max-blank-identifiers: 3
max-blank-identifiers: 6
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
nolintlint:
allow-unused: false
require-explanation: false
require-specific: false
require-specific: false
gosimple:
checks: ["all"]
gocritic:
disabled-checks:
- regexpMust
- appendAssign
- ifElseChain
7 changes: 3 additions & 4 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import (
"time"

"github.com/gogo/protobuf/proto"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"

abci "github.com/tendermint/tendermint/abci/types"
ocabci "github.com/Finschia/ostracon/abci/types"

"github.com/Finschia/finschia-sdk/codec"
snapshottypes "github.com/Finschia/finschia-sdk/snapshots/types"
"github.com/Finschia/finschia-sdk/telemetry"
sdk "github.com/Finschia/finschia-sdk/types"
sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
ocabci "github.com/Finschia/ostracon/abci/types"
)

// InitChain implements the ABCI interface. It runs the initialization logic
Expand Down Expand Up @@ -56,7 +56,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
}

if app.initChainer == nil {
return
return res
tkxkd0159 marked this conversation as resolved.
Show resolved Hide resolved
}

// add block gas meter for any genesis transactions (allow infinite gas)
Expand Down Expand Up @@ -925,7 +925,6 @@ func splitPath(requestPath string) (path []string) {
// createQueryContext creates a new sdk.Context for a query, taking as args
// the block height and whether the query needs a proof or not.
func (app *BaseApp) createQueryContextWithCheckState() sdk.Context {

cacheMS := app.checkState.CacheMultiStore()

// branch the commit-multistore for safety
Expand Down
11 changes: 8 additions & 3 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ func TestBaseAppCreateQueryContext(t *testing.T) {
db := dbm.NewMemDB()
name := t.Name()
app := NewBaseApp(name, logger, db, nil)
app.init()
err := app.init()
require.NoError(t, err)

app.BeginBlock(ocabci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})
app.Commit()
Expand Down Expand Up @@ -190,7 +191,8 @@ func TestBaseAppBeginBlockConsensusParams(t *testing.T) {
},
},
})
app.init()
err := app.init()
require.NoError(t, err)

// set block params
app.BeginBlock(ocabci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})
Expand Down Expand Up @@ -218,7 +220,10 @@ func (ps *paramStore) Set(_ sdk.Context, key []byte, value interface{}) {
panic(err)
}

ps.db.Set(key, bz)
err = ps.db.Set(key, bz)
if err != nil {
panic(err)
}
}

func (ps *paramStore) Has(_ sdk.Context, key []byte) bool {
Expand Down
4 changes: 1 addition & 3 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import (
"sync"

"github.com/gogo/protobuf/proto"

abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

ocabci "github.com/Finschia/ostracon/abci/types"
"github.com/Finschia/ostracon/crypto/tmhash"
"github.com/Finschia/ostracon/libs/log"
dbm "github.com/tendermint/tm-db"

"github.com/Finschia/finschia-sdk/codec/types"
"github.com/Finschia/finschia-sdk/server/config"
Expand Down Expand Up @@ -667,7 +666,6 @@ func (app *BaseApp) anteTx(ctx sdk.Context, txBytes []byte, tx sdk.Tx, simulate
anteCtx, msCache := app.cacheTxContext(ctx, txBytes)
anteCtx = anteCtx.WithEventManager(sdk.NewEventManager())
newCtx, err := app.anteHandler(anteCtx, tx, simulate)

if err != nil {
return newCtx, err
}
Expand Down
11 changes: 3 additions & 8 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func aminoTxEncoder() sdk.TxEncoder {

// simple one store baseapp
func setupBaseApp(t *testing.T, options ...func(*BaseApp)) *BaseApp {
t.Helper()
app := newBaseApp(t.Name(), options...)
require.Equal(t, t.Name(), app.Name())

Expand Down Expand Up @@ -132,6 +133,7 @@ func TestLoadVersionPruning(t *testing.T) {
}

func testLoadVersionHelper(t *testing.T, app *BaseApp, expectedHeight int64, expectedID sdk.CommitID) {
t.Helper()
lastHeight := app.LastBlockHeight()
lastID := app.LastCommitID()
require.Equal(t, expectedHeight, lastHeight)
Expand Down Expand Up @@ -163,13 +165,6 @@ func TestGetMaximumBlockGas(t *testing.T) {
}

func TestListSnapshots(t *testing.T) {
type setupConfig struct {
blocks uint64
blockTxs int
snapshotInterval uint64
snapshotKeepEvery uint32
}

app, _ := setupBaseAppWithSnapshots(t, 2, 5)

expected := abci.ResponseListSnapshots{Snapshots: []*abci.Snapshot{
Expand Down Expand Up @@ -222,7 +217,7 @@ func TestSetChanCheckTxSize(t *testing.T) {
logger := defaultLogger()
db := dbm.NewMemDB()

var size = uint(100)
size := uint(100)

app := NewBaseApp(t.Name(), logger, db, nil, SetChanCheckTxSize(size))
require.Equal(t, int(size), cap(app.chCheckTx))
Expand Down
2 changes: 1 addition & 1 deletion baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
}
}

func createTestTx(txConfig client.TxConfig, txBuilder client.TxBuilder, privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, []byte, error) {
func createTestTx(txConfig client.TxConfig, txBuilder client.TxBuilder, privs []cryptotypes.PrivKey, accNums, accSeqs []uint64, chainID string) (xauthsigning.Tx, []byte, error) {
// First round: we gather all the signer infos. We use the "set empty
// signature" hack to do that.
var sigsV2 []signing.SignatureV2
Expand Down
9 changes: 8 additions & 1 deletion baseapp/deliver_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ func TestCustomRunTxPanicHandler(t *testing.T) {
{
tx := newTxCounter(0, 0)

require.PanicsWithValue(t, customPanicMsg, func() { app.Deliver(aminoTxEncoder(), tx) })
require.PanicsWithValue(t, customPanicMsg, func() { app.Deliver(aminoTxEncoder(), tx) }) //nolint:errcheck
}
}

Expand Down Expand Up @@ -1284,6 +1284,7 @@ func testTxDecoder(cdc *codec.LegacyAmino) sdk.TxDecoder {
}

func anteHandlerTxTest(t *testing.T, capKey sdk.StoreKey, storeKey []byte) sdk.AnteHandler {
t.Helper()
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
store := ctx.KVStore(capKey)
txTest := tx.(txTest)
Expand All @@ -1307,6 +1308,7 @@ func anteHandlerTxTest(t *testing.T, capKey sdk.StoreKey, storeKey []byte) sdk.A

// TODO(dudong2): remove this func after reverting CheckTx logic
func anteHandlerTxTest2(t *testing.T, capKey sdk.StoreKey, storeKey []byte) sdk.AnteHandler {
t.Helper()
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
store := ctx.KVStore(capKey)
txTest := tx.(*txTest)
Expand Down Expand Up @@ -1338,6 +1340,7 @@ func counterEvent(evType string, msgCount int64) sdk.Events {
}

func handlerMsgCounter(t *testing.T, capKey sdk.StoreKey, deliverKey []byte) sdk.Handler {
t.Helper()
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())
store := ctx.KVStore(capKey)
Expand Down Expand Up @@ -1389,6 +1392,7 @@ func setIntOnStore(store sdk.KVStore, key []byte, i int64) {
// check counter matches what's in store.
// increment and store
func incrementingCounter(t *testing.T, store sdk.KVStore, counterKey []byte, counter int64) (*sdk.Result, error) {
t.Helper()
storedCounter := getIntFromStore(store, counterKey)
require.Equal(t, storedCounter, counter)
setIntOnStore(store, counterKey, counter+1)
Expand Down Expand Up @@ -1649,6 +1653,7 @@ func TestLoadVersionInvalid(t *testing.T) {

// simple one store baseapp with data and snapshots. Each tx is 1 MB in size (uncompressed).
func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options ...func(*BaseApp)) (*BaseApp, func()) {
t.Helper()
codec := codec.NewLegacyAmino()
registerTestCodec(codec)
routerOpt := func(bapp *BaseApp) {
Expand Down Expand Up @@ -1785,6 +1790,7 @@ func useDefaultLoader(app *BaseApp) {
}

func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {
t.Helper()
rs := rootmulti.NewStore(db, log.NewNopLogger())
rs.SetPruning(store.PruneNothing)
key := sdk.NewKVStoreKey(storeKey)
Expand All @@ -1802,6 +1808,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {
}

func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) {
t.Helper()
rs := rootmulti.NewStore(db, log.NewNopLogger())
rs.SetPruning(store.PruneDefault)
key := sdk.NewKVStoreKey(storeKey)
Expand Down
Loading
Loading