chore: fix all linting (#24101)

This commit is contained in:
Alex | Interchain Labs
2025-03-21 15:04:36 -07:00
committed by GitHub
parent b7fb7f4858
commit 7fd79df4e1
329 changed files with 1282 additions and 1251 deletions
+4 -4
View File
@@ -75,7 +75,7 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
// when client.toml does not exist create and init with default values
if _, err := os.Stat(configFilePath); os.IsNotExist(err) {
if err := os.MkdirAll(configPath, os.ModePerm); err != nil {
return ctx, fmt.Errorf("couldn't make client config: %v", err)
return ctx, fmt.Errorf("couldn't make client config: %w", err)
}
if ctx.ChainID != "" {
@@ -83,13 +83,13 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
}
if err := writeConfigToFile(configFilePath, conf); err != nil {
return ctx, fmt.Errorf("could not write client config to the file: %v", err)
return ctx, fmt.Errorf("could not write client config to the file: %w", err)
}
}
conf, err := getClientConfig(configPath, ctx.Viper)
if err != nil {
return ctx, fmt.Errorf("couldn't get client config: %v", err)
return ctx, fmt.Errorf("couldn't get client config: %w", err)
}
// we need to update KeyringDir field on Client Context first cause it is used in NewKeyringFromBackend
ctx = ctx.WithOutputFormat(conf.Output).
@@ -106,7 +106,7 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
// https://github.com/cosmos/cosmos-sdk/issues/8986
client, err := client.NewClientFromNode(conf.Node)
if err != nil {
return ctx, fmt.Errorf("couldn't get client from nodeURI: %v", err)
return ctx, fmt.Errorf("couldn't get client from nodeURI: %w", err)
}
ctx = ctx.WithNodeURI(conf.Node).
+7 -7
View File
@@ -16,7 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
legacybech32 "github.com/cosmos/cosmos-sdk/types/bech32/legacybech32" //nolint:staticcheck // we do old keys, they're keys after all.
"github.com/cosmos/cosmos-sdk/types/bech32/legacybech32" //nolint:staticcheck // retain for debug purposes
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/version"
)
@@ -157,17 +157,17 @@ func getPubKeyFromRawString(pkstr, keytype string) (cryptotypes.PubKey, error) {
}
}
pk, err := legacybech32.UnmarshalPubKey(legacybech32.AccPK, pkstr) //nolint:staticcheck // we do old keys, they're keys after all.
pk, err := legacybech32.UnmarshalPubKey(legacybech32.AccPK, pkstr)
if err == nil {
return pk, nil
}
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ValPK, pkstr) //nolint:staticcheck // we do old keys, they're keys after all.
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ValPK, pkstr)
if err == nil {
return pk, nil
}
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ConsPK, pkstr) //nolint:staticcheck // we do old keys, they're keys after all.
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ConsPK, pkstr)
if err == nil {
return pk, nil
}
@@ -206,7 +206,7 @@ func PubkeyRawCmd() *cobra.Command {
var consensusPub string
edPK, ok := pk.(*ed25519.PubKey)
if ok && pubkeyType == ed {
consensusPub, err = legacybech32.MarshalPubKey(legacybech32.ConsPK, edPK) //nolint:staticcheck // we do old keys, they're keys after all.
consensusPub, err = legacybech32.MarshalPubKey(legacybech32.ConsPK, edPK)
if err != nil {
return err
}
@@ -219,11 +219,11 @@ func PubkeyRawCmd() *cobra.Command {
if err != nil {
return err
}
accPub, err := legacybech32.MarshalPubKey(legacybech32.AccPK, pk) //nolint:staticcheck // we do old keys, they're keys after all.
accPub, err := legacybech32.MarshalPubKey(legacybech32.AccPK, pk)
if err != nil {
return err
}
valPub, err := legacybech32.MarshalPubKey(legacybech32.ValPK, pk) //nolint:staticcheck // we do old keys, they're keys after all.
valPub, err := legacybech32.MarshalPubKey(legacybech32.ValPK, pk)
if err != nil {
return err
}
-1
View File
@@ -22,7 +22,6 @@ func TestParseGasSetting(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
gs, err := flags.ParseGasSetting(tc.input)
+1 -1
View File
@@ -51,7 +51,7 @@ var CometBFTAutoCLIDescriptor = &autocliv1.ServiceCommandDescriptor{
// NewCometBFTCommands is a fake `appmodule.Module` to be considered as a module
// and be added in AutoCLI.
func NewCometBFTCommands() *cometModule { //nolint:revive // fake module and limiting import of core
func NewCometBFTCommands() *cometModule {
return &cometModule{}
}
+5 -4
View File
@@ -83,18 +83,19 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.NoError(err)
// init chain will set the validator set and initialize the genesis accounts
app.InitChain(&abci.RequestInitChain{
_, err = app.InitChain(&abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: sims.DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)
})
s.NoError(err)
app.FinalizeBlock(&abci.RequestFinalizeBlock{
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: app.LastBlockHeight() + 1,
Hash: app.LastCommitID().Hash,
NextValidatorsHash: valSet.Hash(),
})
s.NoError(err)
// end of app init
+1 -1
View File
@@ -375,7 +375,7 @@ func printCreate(cmd *cobra.Command, k *keyring.Record, showMnemonic bool, mnemo
// print mnemonic unless requested not to.
if showMnemonic {
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 {
return fmt.Errorf("failed to print mnemonic: %v", err)
return fmt.Errorf("failed to print mnemonic: %w", err)
}
}
case flags.OutputFormatJSON:
-1
View File
@@ -163,7 +163,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())
-1
View File
@@ -202,7 +202,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())
+2 -1
View File
@@ -20,6 +20,8 @@ import (
)
func cleanupKeys(t *testing.T, kb keyring.Keyring, keys ...string) func() {
t.Helper()
return func() {
for _, k := range keys {
if err := kb.Delete(k); err != nil {
@@ -59,7 +61,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),
-1
View File
@@ -25,7 +25,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(), config, tt.args) != nil)
})
+2 -2
View File
@@ -66,14 +66,14 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
if len(args) == 1 {
k, err = fetchKey(clientCtx.Keyring, args[0])
if err != nil {
return fmt.Errorf("%s is not a valid name or address: %v", args[0], err)
return fmt.Errorf("%s is not a valid name or address: %w", args[0], err)
}
} else {
pks := make([]cryptotypes.PubKey, len(args))
for i, keyref := range args {
k, err := fetchKey(clientCtx.Keyring, keyref)
if err != nil {
return fmt.Errorf("%s is not a valid name or address: %v", keyref, err)
return fmt.Errorf("%s is not a valid name or address: %w", keyref, err)
}
key, err := k.GetPubKey()
if err != nil {
-2
View File
@@ -215,7 +215,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)
@@ -241,7 +240,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) {
got, err := getBechKeyOut(tt.args.bechPrefix)
if tt.wantErr {
+2 -1
View File
@@ -4,6 +4,7 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"errors"
"fmt"
"io"
"os"
@@ -77,7 +78,7 @@ func LoadArchiveCmd() *cobra.Command {
for i := uint32(0); i < snapshot.Chunks; i++ {
hdr, err = tr.Next()
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
return err
+2
View File
@@ -229,6 +229,8 @@ func TestAuxTxBuilder(t *testing.T) {
// checkCorrectData that the auxSignerData's content matches the inputs we gave.
func checkCorrectData(t *testing.T, cdc codec.Codec, auxSignerData typestx.AuxSignerData, signMode signing.SignMode) {
t.Helper()
pkAny, err := codectypes.NewAnyWithValue(pub1)
require.NoError(t, err)
msgAny, err := codectypes.NewAnyWithValue(msg1)
+5 -6
View File
@@ -74,7 +74,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)
@@ -83,16 +82,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)
-1
View File
@@ -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)
+1 -1
View File
@@ -48,7 +48,7 @@ func initFixture(t *testing.T) *fixture {
}
}()
clientConn, err := grpc.Dial(listener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
clientConn, err := grpc.NewClient(listener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
assert.NilError(t, err)
encodingConfig := moduletestutil.MakeTestEncodingConfig(bank.AppModuleBasic{})
+3 -2
View File
@@ -14,13 +14,14 @@ var KeyringContextKey struct{}
var _ Keyring = &KeyringImpl{}
type KeyringImpl struct { //nolint:revive // stuttering is fine
type KeyringImpl struct {
k Keyring
}
// NewKeyringInContext returns a new context with the keyring set.
func NewKeyringInContext(ctx context.Context, k Keyring) context.Context {
return context.WithValue(ctx, KeyringContextKey, NewKeyringImpl(k))
// TODO: should this be fixed?
return context.WithValue(ctx, KeyringContextKey, NewKeyringImpl(k)) //nolint:staticcheck // we can ignore this safely until we make a fix for this
}
func NewKeyringImpl(k Keyring) *KeyringImpl {
+4 -2
View File
@@ -8,7 +8,9 @@ import (
"cosmossdk.io/client/v2/internal/strcase"
)
func toKebab(t testing.TB) {
func toKebab(tb testing.TB) {
tb.Helper()
cases := [][]string{
{"testCase", "test-case"},
{"TestCase", "test-case"},
@@ -28,7 +30,7 @@ func toKebab(t testing.TB) {
in := i[0]
out := i[1]
result := strcase.ToKebab(in)
assert.Equal(t, out, result, "ToKebab(%s) = %s, want %s", in, result, out)
assert.Equal(tb, out, result, "ToKebab(%s) = %s, want %s", in, result, out)
}
}