Skip to content

Commit

Permalink
chore: bump golangci-lint and fix all linting issues (cosmos#21761)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Sep 16, 2024
1 parent 52ba264 commit cbdfd9b
Show file tree
Hide file tree
Showing 186 changed files with 114 additions and 455 deletions.
12 changes: 6 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ linters:
- dogsled
- errcheck
- errorlint
- exportloopref
- copyloopvar
- gci
- goconst
- gocritic
Expand Down Expand Up @@ -45,15 +45,15 @@ issues:
- crypto/keys/secp256k1/internal/*
- types/coin_regex.go
exclude-rules:
- text: "ST1003:"
- text: "ST1003:" # We are fine with our current naming
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
- text: "ST1016:" # Ok with inconsistent receiver names
linters:
- stylecheck
- path: "migrations"
- path: "migrations" # migraitions always use deprecated code
text: "SA1019:"
linters:
- staticcheck
Expand All @@ -72,9 +72,9 @@ issues:
- text: "SA1019: params.SendEnabled is deprecated" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1029: Inappropriate key in context.WithValue" # TODO remove this when dependency is updated
- text: "G115: integer overflow conversion" # We are doing this everywhere.
linters:
- staticcheck
- gosec
- text: "leading space"
linters:
- nolintlint
Expand Down
3 changes: 1 addition & 2 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,6 @@ func TestABCI_GetBlockRetentionHeight(t *testing.T) {
}

for name, tc := range testCases {
tc := tc

tc.bapp.SetParamStore(&paramStore{db: coretesting.NewMemDB()})
_, err := tc.bapp.InitChain(&abci.InitChainRequest{
Expand Down Expand Up @@ -2081,7 +2080,7 @@ func TestABCI_PrepareProposal_VoteExtensions(t *testing.T) {
return nil, err
}

cp := ctx.ConsensusParams() // nolint:staticcheck // ignore linting error
cp := ctx.ConsensusParams() //nolint:staticcheck // ignore linting error
extsEnabled := cp.Feature.VoteExtensionsEnableHeight != nil && req.Height >= cp.Feature.VoteExtensionsEnableHeight.Value && cp.Feature.VoteExtensionsEnableHeight.Value != 0
if !extsEnabled {
// check abci params
Expand Down
6 changes: 3 additions & 3 deletions baseapp/abci_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func ValidateVoteExtensions(
extCommit abci.ExtendedCommitInfo,
) error {
// Get values from context
cp := ctx.ConsensusParams() // nolint:staticcheck // ignore linting error
cp := ctx.ConsensusParams() //nolint:staticcheck // ignore linting error
currentHeight := ctx.HeaderInfo().Height
chainID := ctx.HeaderInfo().ChainID
commitInfo := ctx.CometInfo().LastCommit
Expand Down Expand Up @@ -258,7 +258,7 @@ func (h *DefaultProposalHandler) SetTxSelector(ts TxSelector) {
func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
return func(ctx sdk.Context, req *abci.PrepareProposalRequest) (*abci.PrepareProposalResponse, error) {
var maxBlockGas uint64
if b := ctx.ConsensusParams().Block; b != nil { // nolint:staticcheck // ignore linting error
if b := ctx.ConsensusParams().Block; b != nil { //nolint:staticcheck // ignore linting error
maxBlockGas = uint64(b.MaxGas)
}

Expand Down Expand Up @@ -405,7 +405,7 @@ func (h *DefaultProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHan
var totalTxGas uint64

var maxBlockGas int64
if b := ctx.ConsensusParams().Block; b != nil { // nolint:staticcheck // ignore linting error
if b := ctx.ConsensusParams().Block; b != nil { //nolint:staticcheck // ignore linting error
maxBlockGas = b.MaxGas
}

Expand Down
2 changes: 1 addition & 1 deletion baseapp/internal/protocompat/protocompat.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"reflect"

gogoproto "github.com/cosmos/gogoproto/proto"
"github.com/golang/protobuf/proto" // nolint: staticcheck // needed because gogoproto.Merge does not work consistently. See NOTE: comments.
"github.com/golang/protobuf/proto" //nolint: staticcheck // needed because gogoproto.Merge does not work consistently. See NOTE: comments.
"google.golang.org/grpc"
proto2 "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
Expand Down
1 change: 0 additions & 1 deletion baseapp/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ func TestABCI_OfferSnapshot_Errors(t *testing.T) {
}, abci.OFFER_SNAPSHOT_RESULT_REJECT},
}
for name, tc := range testCases {
tc := tc
t.Run(name, func(t *testing.T) {
resp, err := suite.baseApp.OfferSnapshot(&abci.OfferSnapshotRequest{Snapshot: tc.snapshot})
require.NoError(t, err)
Expand Down
2 changes: 0 additions & 2 deletions client/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ func TestSetCmdClientContextHandler(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
cmd := newCmd()
_ = testutil.ApplyMockIODiscardOutErr(cmd)
Expand Down
1 change: 0 additions & 1 deletion client/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func TestConfigCmdEnvFlag(t *testing.T) {
}

for _, tc := range tt {
tc := tc
t.Run(tc.name, func(t *testing.T) {
testCmd := &cobra.Command{
Use: "test",
Expand Down
2 changes: 0 additions & 2 deletions client/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ func TestParseGasSetting(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
gs, err := flags.ParseGasSetting(tc.input)

Expand Down
1 change: 0 additions & 1 deletion client/keys/add_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func Test_runAddCmdLedgerDryRun(t *testing.T) {
}

for _, tt := range testData {
tt := tt
t.Run(tt.name, func(t *testing.T) {
cmd := AddKeyCommand()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
Expand Down
1 change: 0 additions & 1 deletion client/keys/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ func Test_runAddCmdDryRun(t *testing.T) {
},
}
for _, tt := range testData {
tt := tt
t.Run(tt.name, func(t *testing.T) {
cmd := AddKeyCommand()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
Expand Down
1 change: 0 additions & 1 deletion client/keys/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func Test_runListCmd(t *testing.T) {
{"keybase: w/key", kbHome2, false},
}
for _, tt := range testData {
tt := tt
t.Run(tt.name, func(t *testing.T) {
cmd.SetArgs([]string{
fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, tt.kbDir),
Expand Down
1 change: 0 additions & 1 deletion client/keys/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func TestParseKey(t *testing.T) {
{"hex", []string{hexstr}, false},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.wantErr, doParseKey(ParseKeyStringCommand(), "cosmos", tt.args) != nil)
})
Expand Down
2 changes: 0 additions & 2 deletions client/keys/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ func Test_validateMultisigThreshold(t *testing.T) {
{"1-2", args{2, 1}, true},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if err := validateMultisigThreshold(tt.args.k, tt.args.nKeys); (err != nil) != tt.wantErr {
t.Errorf("validateMultisigThreshold() error = %v, wantErr %v", err, tt.wantErr)
Expand Down Expand Up @@ -272,7 +271,6 @@ func Test_getBechKeyOut(t *testing.T) {
{"cons", args{sdk.PrefixConsensus}, MkConsKeyOutput, false},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
output, err := getKeyOutput(ctx, tt.args.bechPrefix, k)
if tt.wantErr {
Expand Down
1 change: 0 additions & 1 deletion client/tx/aux_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func TestAuxTxBuilder(t *testing.T) {
}

for _, tc := range testcases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
b = tx.NewAuxTxBuilder()
err := tc.malleate()
Expand Down
11 changes: 5 additions & 6 deletions client/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func TestCalculateGas(t *testing.T) {
}

for _, tc := range testCases {
stc := tc
txCfg, _ := newTestTxConfig()
defaultSignMode, err := signing.APISignModeToInternal(txCfg.SignModeHandler().DefaultMode())
require.NoError(t, err)
Expand All @@ -90,16 +89,16 @@ func TestCalculateGas(t *testing.T) {
WithChainID("test-chain").
WithTxConfig(txCfg).WithSignMode(defaultSignMode)

t.Run(stc.name, func(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
mockClientCtx := mockContext{
gasUsed: tc.args.mockGasUsed,
wantErr: tc.args.mockWantErr,
}
simRes, gotAdjusted, err := CalculateGas(mockClientCtx, txf.WithGasAdjustment(stc.args.adjustment))
if stc.expPass {
simRes, gotAdjusted, err := CalculateGas(mockClientCtx, txf.WithGasAdjustment(tc.args.adjustment))
if tc.expPass {
require.NoError(t, err)
require.Equal(t, simRes.GasInfo.GasUsed, stc.wantEstimate)
require.Equal(t, gotAdjusted, stc.wantAdjusted)
require.Equal(t, simRes.GasInfo.GasUsed, tc.wantEstimate)
require.Equal(t, gotAdjusted, tc.wantAdjusted)
require.NotNil(t, simRes.Result)
} else {
require.Error(t, err)
Expand Down
1 change: 0 additions & 1 deletion client/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func TestPaginate(t *testing.T) {
}

for i, tc := range testCases {
i, tc := i, tc
t.Run(tc.name, func(t *testing.T) {
start, end := client.Paginate(tc.numObjs, tc.page, tc.limit, tc.defLimit)
require.Equal(t, tc.expectedStart, start, "invalid result; test case #%d", i)
Expand Down
2 changes: 0 additions & 2 deletions codec/amino_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ func TestAminoCodecMarshalJSONIndent(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
cdc := codec.NewAminoCodec(createTestCodec())
bz, err := cdc.MarshalJSONIndent(tc.input, "", " ")
Expand Down
2 changes: 1 addition & 1 deletion codec/codec_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func testMarshaling(t *testing.T, cdc interface {
}

for _, tc := range testCases {
tc := tc

m1 := mustMarshaler{cdc.Marshal, cdc.MustMarshal, cdc.Unmarshal, cdc.MustUnmarshal}
m2 := mustMarshaler{cdc.MarshalLengthPrefixed, cdc.MustMarshalLengthPrefixed, cdc.UnmarshalLengthPrefixed, cdc.MustUnmarshalLengthPrefixed}
m3 := mustMarshaler{
Expand Down
1 change: 0 additions & 1 deletion codec/unknownproto/unit_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestWireTypeToString(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("wireType=%d", tt.typ), func(t *testing.T) {
if g, w := wireTypeToString(tt.typ), tt.want; g != w {
t.Fatalf("Mismatch:\nGot: %q\nWant: %q\n", g, w)
Expand Down
4 changes: 0 additions & 4 deletions codec/unknownproto/unknown_fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ func TestRejectUnknownFieldsRepeated(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
protoBlob, err := proto.Marshal(tt.in)
if err != nil {
Expand Down Expand Up @@ -280,7 +279,6 @@ func TestRejectUnknownFields_allowUnknownNonCriticals(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
blob, err := proto.Marshal(tt.in)
if err != nil {
Expand Down Expand Up @@ -483,7 +481,6 @@ func TestRejectUnknownFieldsNested(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
protoBlob, err := proto.Marshal(tt.in)
if err != nil {
Expand Down Expand Up @@ -634,7 +631,6 @@ func TestRejectUnknownFieldsFlat(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
blob, err := proto.Marshal(tt.in)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions crypto/hd/hdpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ func TestCreateHDPath(t *testing.T) {
{"m/44'/114'/1'/1/0", args{114, 1, 1}, hd.BIP44Params{Purpose: 44, CoinType: 114, Account: 1, AddressIndex: 1}},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
tt := tt
require.Equal(t, tt.want, *hd.CreateHDPath(tt.args.coinType, tt.args.account, tt.args.index))
})
}
Expand Down Expand Up @@ -170,7 +168,6 @@ func TestDeriveHDPathRange(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.path, func(t *testing.T) {
master, ch := hd.ComputeMastersFromSeed(seed)
_, err := hd.DerivePrivateKeyForPath(master, ch, tt.path)
Expand Down Expand Up @@ -297,7 +294,6 @@ func TestDerivePrivateKeyForPathDoNotCrash(t *testing.T) {
}

for _, path := range paths {
path := path
t.Run(path, func(t *testing.T) {
_, _ = hd.DerivePrivateKeyForPath([32]byte{}, [32]byte{}, path)
})
Expand Down
2 changes: 1 addition & 1 deletion crypto/keyring/keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ func TestRenameKey(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

kr := newKeyring(t, "testKeyring")
t.Run(tc.name, func(t *testing.T) {
tc.run(kr)
Expand Down
1 change: 0 additions & 1 deletion crypto/keyring/signing_algorithms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func TestNewSigningAlgoByString(t *testing.T) {

list := SigningAlgoList{hd.Secp256k1}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
algorithm, err := NewSigningAlgoFromString(tt.algoStr, list)
if tt.isSupported {
Expand Down
6 changes: 3 additions & 3 deletions crypto/keys/secp256k1/secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/cometbft/cometbft/crypto"
secp256k1dcrd "github.com/decred/dcrd/dcrec/secp256k1/v4"
"gitlab.com/yawning/secp256k1-voi/secec"
"golang.org/x/crypto/ripemd160" //nolint: staticcheck // keep around for backwards compatibility
"golang.org/x/crypto/ripemd160" //nolint:staticcheck,gosec // keep around for backwards compatibility

errorsmod "cosmossdk.io/errors"

Expand Down Expand Up @@ -173,8 +173,8 @@ func (pubKey *PubKey) Address() crypto.Address {
}

sha := sha256.Sum256(pubKey.Key)
hasherRIPEMD160 := ripemd160.New()
hasherRIPEMD160.Write(sha[:]) // does not error
hasherRIPEMD160 := ripemd160.New() //nolint:gosec // keep around for backwards compatibility
hasherRIPEMD160.Write(sha[:]) // does not error
return crypto.Address(hasherRIPEMD160.Sum(nil))
}

Expand Down
1 change: 0 additions & 1 deletion crypto/keys/secp256k1/secp256k1_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func Test_genPrivKey(t *testing.T) {
{"valid because 0 < 1 < N", validOne, false},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if tt.shouldPanic {
require.Panics(t, func() {
Expand Down
1 change: 0 additions & 1 deletion crypto/keys/secp256k1/secp256k1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ func TestGenPrivKeyFromSecret(t *testing.T) {
{"another seed used in cosmos tests #3", []byte("")},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
gotPrivKey := secp256k1.GenPrivKeyFromSecret(tt.secret)
require.NotNil(t, gotPrivKey)
Expand Down
6 changes: 0 additions & 6 deletions crypto/types/compact_bit_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestBitArrayEqual(t *testing.T) {
{name: "different should not be equal", b1: big1, b2: big2, eq: false},
}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
eq := tc.b1.Equal(tc.b2)
require.Equal(t, tc.eq, eq)
Expand Down Expand Up @@ -102,7 +101,6 @@ func TestJSONMarshalUnmarshal(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.bA.String(), func(t *testing.T) {
bz, err := json.Marshal(tc.bA)
require.NoError(t, err)
Expand Down Expand Up @@ -162,7 +160,6 @@ func TestCompactMarshalUnmarshal(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.bA.String(), func(t *testing.T) {
bz := tc.bA.CompactMarshal()

Expand Down Expand Up @@ -209,8 +206,6 @@ func TestCompactBitArrayNumOfTrueBitsBefore(t *testing.T) {
{`"______________xx"`, []int{14, 15}, []int{0, 1}},
}
for tcIndex, tc := range testCases {
tc := tc
tcIndex := tcIndex
t.Run(tc.marshalledBA, func(t *testing.T) {
var bA *CompactBitArray
err := json.Unmarshal([]byte(tc.marshalledBA), &bA)
Expand Down Expand Up @@ -283,7 +278,6 @@ func TestNewCompactBitArrayCrashWithLimits(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("%d", tt.in), func(t *testing.T) {
got := NewCompactBitArray(tt.in)
if g := got != nil; g != tt.mustPass {
Expand Down
Loading

0 comments on commit cbdfd9b

Please sign in to comment.