Skip to content

Commit 550b3fe

Browse files
committed
autofixes
1 parent b3cad59 commit 550b3fe

File tree

149 files changed

+116
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+116
-346
lines changed

.golangci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ linters:
3232
- typecheck
3333
- unconvert
3434
- unused
35+
- usetesting
3536

3637
issues:
3738
exclude-dirs:
@@ -118,6 +119,5 @@ linters-settings:
118119
disabled-checks:
119120
- regexpMust
120121
- appendAssign
121-
- ifElseChain
122122
unused:
123-
local-variables-are-used: false
123+
local-variables-are-used: false

baseapp/abci_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,6 @@ func TestABCI_GetBlockRetentionHeight(t *testing.T) {
13361336
}
13371337

13381338
for name, tc := range testCases {
1339-
tc := tc
13401339

13411340
tc.bapp.SetParamStore(&paramStore{db: dbm.NewMemDB()})
13421341
_, err = tc.bapp.InitChain(&abci.RequestInitChain{

baseapp/abci_utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"slices" //nolint: gci // ignore this line for this linter
7+
"slices"
88

99
"github.com/cockroachdb/errors"
1010
abci "github.com/cometbft/cometbft/abci/types"
1111
cryptoenc "github.com/cometbft/cometbft/crypto/encoding"
1212
cmtprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
1313
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
1414
protoio "github.com/cosmos/gogoproto/io"
15-
"github.com/cosmos/gogoproto/proto" //nolint: gci // ignore this line for this linter
15+
"github.com/cosmos/gogoproto/proto"
1616

1717
"cosmossdk.io/core/comet"
1818

baseapp/snapshot_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ func TestABCI_OfferSnapshot_Errors(t *testing.T) {
245245
}, abci.ResponseOfferSnapshot_REJECT},
246246
}
247247
for name, tc := range testCases {
248-
tc := tc
249248
t.Run(name, func(t *testing.T) {
250249
resp, err := suite.baseApp.OfferSnapshot(&abci.RequestOfferSnapshot{Snapshot: tc.snapshot})
251250
require.NoError(t, err)

client/cmd_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ func TestSetCmdClientContextHandler(t *testing.T) {
125125
}
126126

127127
for _, tc := range testCases {
128-
tc := tc
129-
130128
t.Run(tc.name, func(t *testing.T) {
131129
cmd := newCmd()
132130
_ = testutil.ApplyMockIODiscardOutErr(cmd)

client/config/config.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,21 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
7575
// when client.toml does not exist create and init with default values
7676
if _, err := os.Stat(configFilePath); os.IsNotExist(err) {
7777
if err := os.MkdirAll(configPath, os.ModePerm); err != nil {
78-
return ctx, fmt.Errorf("couldn't make client config: %v", err)
78+
return ctx, fmt.Errorf("couldn't make client config: %w", err)
7979
}
8080

8181
if ctx.ChainID != "" {
8282
conf.ChainID = ctx.ChainID // chain-id will be written to the client.toml while initiating the chain.
8383
}
8484

8585
if err := writeConfigToFile(configFilePath, conf); err != nil {
86-
return ctx, fmt.Errorf("could not write client config to the file: %v", err)
86+
return ctx, fmt.Errorf("could not write client config to the file: %w", err)
8787
}
8888
}
8989

9090
conf, err := getClientConfig(configPath, ctx.Viper)
9191
if err != nil {
92-
return ctx, fmt.Errorf("couldn't get client config: %v", err)
92+
return ctx, fmt.Errorf("couldn't get client config: %w", err)
9393
}
9494
// we need to update KeyringDir field on Client Context first cause it is used in NewKeyringFromBackend
9595
ctx = ctx.WithOutputFormat(conf.Output).
@@ -106,7 +106,7 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
106106
// https://github.com/cosmos/cosmos-sdk/issues/8986
107107
client, err := client.NewClientFromNode(conf.Node)
108108
if err != nil {
109-
return ctx, fmt.Errorf("couldn't get client from nodeURI: %v", err)
109+
return ctx, fmt.Errorf("couldn't get client from nodeURI: %w", err)
110110
}
111111

112112
ctx = ctx.WithNodeURI(conf.Node).

client/config/config_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ func TestConfigCmdEnvFlag(t *testing.T) {
5858
}
5959

6060
for _, tc := range tt {
61-
tc := tc
6261
t.Run(tc.name, func(t *testing.T) {
6362
testCmd := &cobra.Command{
6463
Use: "test",

client/debug/main.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,17 @@ func getPubKeyFromRawString(pkstr, keytype string) (cryptotypes.PubKey, error) {
157157
}
158158
}
159159

160-
pk, err := legacybech32.UnmarshalPubKey(legacybech32.AccPK, pkstr) //nolint:staticcheck // we do old keys, they're keys after all.
160+
pk, err := legacybech32.UnmarshalPubKey(legacybech32.AccPK, pkstr)
161161
if err == nil {
162162
return pk, nil
163163
}
164164

165-
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ValPK, pkstr) //nolint:staticcheck // we do old keys, they're keys after all.
165+
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ValPK, pkstr)
166166
if err == nil {
167167
return pk, nil
168168
}
169169

170-
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ConsPK, pkstr) //nolint:staticcheck // we do old keys, they're keys after all.
170+
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ConsPK, pkstr)
171171
if err == nil {
172172
return pk, nil
173173
}
@@ -206,7 +206,7 @@ func PubkeyRawCmd() *cobra.Command {
206206
var consensusPub string
207207
edPK, ok := pk.(*ed25519.PubKey)
208208
if ok && pubkeyType == ed {
209-
consensusPub, err = legacybech32.MarshalPubKey(legacybech32.ConsPK, edPK) //nolint:staticcheck // we do old keys, they're keys after all.
209+
consensusPub, err = legacybech32.MarshalPubKey(legacybech32.ConsPK, edPK)
210210
if err != nil {
211211
return err
212212
}
@@ -219,11 +219,11 @@ func PubkeyRawCmd() *cobra.Command {
219219
if err != nil {
220220
return err
221221
}
222-
accPub, err := legacybech32.MarshalPubKey(legacybech32.AccPK, pk) //nolint:staticcheck // we do old keys, they're keys after all.
222+
accPub, err := legacybech32.MarshalPubKey(legacybech32.AccPK, pk)
223223
if err != nil {
224224
return err
225225
}
226-
valPub, err := legacybech32.MarshalPubKey(legacybech32.ValPK, pk) //nolint:staticcheck // we do old keys, they're keys after all.
226+
valPub, err := legacybech32.MarshalPubKey(legacybech32.ValPK, pk)
227227
if err != nil {
228228
return err
229229
}

client/flags/flags_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ func TestParseGasSetting(t *testing.T) {
2222
}
2323

2424
for _, tc := range testCases {
25-
tc := tc
26-
2725
t.Run(tc.name, func(t *testing.T) {
2826
gs, err := flags.ParseGasSetting(tc.input)
2927

client/grpc/cmtservice/autocli.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var CometBFTAutoCLIDescriptor = &autocliv1.ServiceCommandDescriptor{
5151

5252
// NewCometBFTCommands is a fake `appmodule.Module` to be considered as a module
5353
// and be added in AutoCLI.
54-
func NewCometBFTCommands() *cometModule { //nolint:revive // fake module and limiting import of core
54+
func NewCometBFTCommands() *cometModule {
5555
return &cometModule{}
5656
}
5757

client/keys/add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func printCreate(cmd *cobra.Command, k *keyring.Record, showMnemonic bool, mnemo
375375
// print mnemonic unless requested not to.
376376
if showMnemonic {
377377
if _, err := fmt.Fprintf(cmd.ErrOrStderr(), "\n**Important** write this mnemonic phrase in a safe place.\nIt is the only way to recover your account if you ever forget your password.\n\n%s\n", mnemonic); err != nil {
378-
return fmt.Errorf("failed to print mnemonic: %v", err)
378+
return fmt.Errorf("failed to print mnemonic: %w", err)
379379
}
380380
}
381381
case flags.OutputFormatJSON:

client/keys/add_ledger_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ func Test_runAddCmdLedgerDryRun(t *testing.T) {
163163
}
164164

165165
for _, tt := range testData {
166-
tt := tt
167166
t.Run(tt.name, func(t *testing.T) {
168167
cmd := AddKeyCommand()
169168
cmd.Flags().AddFlagSet(Commands().PersistentFlags())

client/keys/add_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ func Test_runAddCmdDryRun(t *testing.T) {
202202
},
203203
}
204204
for _, tt := range testData {
205-
tt := tt
206205
t.Run(tt.name, func(t *testing.T) {
207206
cmd := AddKeyCommand()
208207
cmd.Flags().AddFlagSet(Commands().PersistentFlags())

client/keys/list_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func Test_runListCmd(t *testing.T) {
5959
{"keybase: w/key", kbHome2, false},
6060
}
6161
for _, tt := range testData {
62-
tt := tt
6362
t.Run(tt.name, func(t *testing.T) {
6463
cmd.SetArgs([]string{
6564
fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, tt.kbDir),

client/keys/parse_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ func TestParseKey(t *testing.T) {
2525
{"hex", []string{hexstr}, false},
2626
}
2727
for _, tt := range tests {
28-
tt := tt
2928
t.Run(tt.name, func(t *testing.T) {
3029
require.Equal(t, tt.wantErr, doParseKey(ParseKeyStringCommand(), config, tt.args) != nil)
3130
})

client/keys/show.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
6363
if len(args) == 1 {
6464
k, err = fetchKey(clientCtx.Keyring, args[0])
6565
if err != nil {
66-
return fmt.Errorf("%s is not a valid name or address: %v", args[0], err)
66+
return fmt.Errorf("%s is not a valid name or address: %w", args[0], err)
6767
}
6868
} else {
6969
pks := make([]cryptotypes.PubKey, len(args))
7070
for i, keyref := range args {
7171
k, err := fetchKey(clientCtx.Keyring, keyref)
7272
if err != nil {
73-
return fmt.Errorf("%s is not a valid name or address: %v", keyref, err)
73+
return fmt.Errorf("%s is not a valid name or address: %w", keyref, err)
7474
}
7575
key, err := k.GetPubKey()
7676
if err != nil {

client/keys/show_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ func Test_validateMultisigThreshold(t *testing.T) {
186186
{"1-2", args{2, 1}, true},
187187
}
188188
for _, tt := range tests {
189-
tt := tt
190189
t.Run(tt.name, func(t *testing.T) {
191190
if err := validateMultisigThreshold(tt.args.k, tt.args.nKeys); (err != nil) != tt.wantErr {
192191
t.Errorf("validateMultisigThreshold() error = %v, wantErr %v", err, tt.wantErr)
@@ -212,7 +211,6 @@ func Test_getBechKeyOut(t *testing.T) {
212211
{"cons", args{sdk.PrefixConsensus}, MkConsKeyOutput, false},
213212
}
214213
for _, tt := range tests {
215-
tt := tt
216214
t.Run(tt.name, func(t *testing.T) {
217215
got, err := getBechKeyOut(tt.args.bechPrefix)
218216
if tt.wantErr {

client/tx/aux_builder_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ func TestAuxTxBuilder(t *testing.T) {
213213
}
214214

215215
for _, tc := range testcases {
216-
tc := tc
217216
t.Run(tc.name, func(t *testing.T) {
218217
b = tx.NewAuxTxBuilder()
219218
err := tc.malleate()

codec/amino_codec_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ func TestAminoCodecMarshalJSONIndent(t *testing.T) {
7171
}
7272

7373
for _, tc := range testCases {
74-
tc := tc
75-
7674
t.Run(tc.name, func(t *testing.T) {
7775
cdc := codec.NewAminoCodec(createTestCodec())
7876
bz, err := cdc.MarshalJSONIndent(tc.input, "", " ")

codec/codec_common_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func testMarshaling(t *testing.T, cdc interface {
121121
}
122122

123123
for _, tc := range testCases {
124-
tc := tc
124+
125125
m1 := mustMarshaler{cdc.Marshal, cdc.MustMarshal, cdc.Unmarshal, cdc.MustUnmarshal}
126126
m2 := mustMarshaler{cdc.MarshalLengthPrefixed, cdc.MustMarshalLengthPrefixed, cdc.UnmarshalLengthPrefixed, cdc.MustUnmarshalLengthPrefixed}
127127
m3 := mustMarshaler{

codec/types/any.go

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
1212
)
1313

14-
// nolint:revive // XXX is reqired for proto compatibility
1514
type Any struct {
1615
// A URL/resource name that uniquely identifies the type of the serialized
1716
// protocol buffer message. This string must contain at least

codec/types/any_internal_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (d Dog) Greet() string { return d.Name }
1717
func (d *Dog) Reset() { d.Name = "" }
1818
func (d *Dog) String() string { return d.Name }
1919
func (d *Dog) ProtoMessage() {}
20-
func (d *Dog) XXX_MessageName() string { return "tests/dog" } //nolint:revive // XXX_ prefix is required
20+
func (d *Dog) XXX_MessageName() string { return "tests/dog" }
2121

2222
type Animal interface {
2323
Greet() string

codec/types/any_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var _ proto.Message = (*errOnMarshal)(nil)
1919

2020
var errAlways = fmt.Errorf("always erroring")
2121

22-
func (eom *errOnMarshal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { //nolint:revive // XXX_ prefix is intentional
22+
func (eom *errOnMarshal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
2323
return nil, errAlways
2424
}
2525

codec/types/types_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var (
4444
func (dog FakeDog) Reset() {}
4545
func (dog FakeDog) String() string { return "fakedog" }
4646
func (dog FakeDog) ProtoMessage() {}
47-
func (dog FakeDog) XXX_MessageName() string { return proto.MessageName(&testdata.Dog{}) } //nolint:revive // XXX_ prefix is intentional
47+
func (dog FakeDog) XXX_MessageName() string { return proto.MessageName(&testdata.Dog{}) }
4848
func (dog FakeDog) Greet() string { return "fakedog" }
4949

5050
func TestRegister(t *testing.T) {

codec/unknownproto/unit_helpers_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func TestWireTypeToString(t *testing.T) {
2222
}
2323

2424
for _, tt := range tests {
25-
tt := tt
2625
t.Run(fmt.Sprintf("wireType=%d", tt.typ), func(t *testing.T) {
2726
if g, w := wireTypeToString(tt.typ), tt.want; g != w {
2827
t.Fatalf("Mismatch:\nGot: %q\nWant: %q\n", g, w)

codec/unknownproto/unknown_fields_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ func TestRejectUnknownFieldsRepeated(t *testing.T) {
223223
}
224224

225225
for _, tt := range tests {
226-
tt := tt
227226
t.Run(tt.name, func(t *testing.T) {
228227
protoBlob, err := proto.Marshal(tt.in)
229228
if err != nil {
@@ -280,7 +279,6 @@ func TestRejectUnknownFields_allowUnknownNonCriticals(t *testing.T) {
280279
}
281280

282281
for _, tt := range tests {
283-
tt := tt
284282
t.Run(tt.name, func(t *testing.T) {
285283
blob, err := proto.Marshal(tt.in)
286284
if err != nil {
@@ -483,7 +481,6 @@ func TestRejectUnknownFieldsNested(t *testing.T) {
483481
}
484482

485483
for _, tt := range tests {
486-
tt := tt
487484
t.Run(tt.name, func(t *testing.T) {
488485
protoBlob, err := proto.Marshal(tt.in)
489486
if err != nil {
@@ -634,7 +631,6 @@ func TestRejectUnknownFieldsFlat(t *testing.T) {
634631
}
635632

636633
for _, tt := range tests {
637-
tt := tt
638634
t.Run(tt.name, func(t *testing.T) {
639635
blob, err := proto.Marshal(tt.in)
640636
if err != nil {

crypto/armor.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func UnarmorInfoBytes(armorStr string) ([]byte, error) {
104104
func UnarmorPubKeyBytes(armorStr string) (bz []byte, algo string, err error) {
105105
bz, header, err := unarmorBytes(armorStr, blockTypePubKey)
106106
if err != nil {
107-
return nil, "", fmt.Errorf("couldn't unarmor bytes: %v", err)
107+
return nil, "", fmt.Errorf("couldn't unarmor bytes: %w", err)
108108
}
109109

110110
switch header[headerVersion] {
@@ -261,15 +261,15 @@ func EncodeArmor(blockType string, headers map[string]string, data []byte) strin
261261
buf := new(bytes.Buffer)
262262
w, err := armor.Encode(buf, blockType, headers)
263263
if err != nil {
264-
panic(fmt.Errorf("could not encode ascii armor: %s", err))
264+
panic(fmt.Errorf("could not encode ascii armor: %w", err))
265265
}
266266
_, err = w.Write(data)
267267
if err != nil {
268-
panic(fmt.Errorf("could not encode ascii armor: %s", err))
268+
panic(fmt.Errorf("could not encode ascii armor: %w", err))
269269
}
270270
err = w.Close()
271271
if err != nil {
272-
panic(fmt.Errorf("could not encode ascii armor: %s", err))
272+
panic(fmt.Errorf("could not encode ascii armor: %w", err))
273273
}
274274
return buf.String()
275275
}

crypto/hd/hdpath_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ func TestCreateHDPath(t *testing.T) {
106106
{"m/44'/114'/1'/1/0", args{114, 1, 1}, hd.BIP44Params{Purpose: 44, CoinType: 114, Account: 1, AddressIndex: 1}},
107107
}
108108
for _, tt := range tests {
109-
tt := tt
110109
t.Run(tt.name, func(t *testing.T) {
111110
tt := tt
112111
require.Equal(t, tt.want, *hd.CreateHDPath(tt.args.coinType, tt.args.account, tt.args.index))
@@ -169,7 +168,6 @@ func TestDeriveHDPathRange(t *testing.T) {
169168
}
170169

171170
for _, tt := range tests {
172-
tt := tt
173171
t.Run(tt.path, func(t *testing.T) {
174172
master, ch := hd.ComputeMastersFromSeed(seed)
175173
_, err := hd.DerivePrivateKeyForPath(master, ch, tt.path)
@@ -298,7 +296,6 @@ func TestDerivePrivateKeyForPathDoNotCrash(t *testing.T) {
298296
}
299297

300298
for _, path := range paths {
301-
path := path
302299
t.Run(path, func(t *testing.T) {
303300
_, _ = hd.DerivePrivateKeyForPath([32]byte{}, [32]byte{}, path)
304301
})

crypto/keyring/keyring.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ func SignWithLedger(k *Record, msg []byte, signMode signing.SignMode) (sig []byt
615615

616616
priv, err := ledger.NewPrivKeySecp256k1Unsafe(*path)
617617
if err != nil {
618-
return
618+
return sig, pub, err
619619
}
620620
ledgerPubKey := priv.PubKey()
621621
pubKey, err := k.GetPubKey()

0 commit comments

Comments
 (0)