Skip to content

Commit

Permalink
style: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tkxkd0159 committed Feb 8, 2024
1 parent 135b2e3 commit 7f34955
Show file tree
Hide file tree
Showing 23 changed files with 157 additions and 78 deletions.
12 changes: 8 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
run:
tests: true
timeout: 15m
sort-results: true
allow-parallel-runners: true
skip-files:
- ".*\\.pb\\.go$"
- ".*\\.pb\\.gw\\.go$"
- ".*\\.pulsar\\.go$"

output:
sort-results: true

linters:
disable-all: true
enable:
- depguard
- dogsled
- exportloopref
- gci
- goconst
- gocritic
- gci
- gofumpt
- gosec
- gosimple
Expand All @@ -25,8 +26,8 @@ linters:
- misspell
- nakedret
- nolintlint
- staticcheck
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
Expand Down Expand Up @@ -59,6 +60,9 @@ issues:
- text: "leading space"
linters:
- nolintlint
- text: "SA1019: collection." # TODO: remove deprecated collection features later
linters:
- staticcheck
max-issues-per-linter: 10000
max-same-issues: 10000

Expand Down
2 changes: 1 addition & 1 deletion simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"

collectionmodule "github.com/Finschia/finschia-sdk/x/foundation/module"
collectionmodule "github.com/Finschia/finschia-sdk/x/collection/module"
foundationmodule "github.com/Finschia/finschia-sdk/x/foundation/module"
)

Expand Down
4 changes: 2 additions & 2 deletions simapp/simd/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ custom-field = "{{ .Custom.CustomField }}"`
func initRootCmd(
rootCmd *cobra.Command,
txConfig client.TxConfig,
interfaceRegistry codectypes.InterfaceRegistry,
appCodec codec.Codec,
_ codectypes.InterfaceRegistry,
_ codec.Codec,
basicManager module.BasicManager,
) {
cfg := sdk.GetConfig()
Expand Down
2 changes: 1 addition & 1 deletion simapp/simd/cmd/root_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func ProvideClientContext(
return clientCtx
}

func ProvideKeyring(clientCtx client.Context, addressCodec address.Codec) (clientv2keyring.Keyring, error) {
func ProvideKeyring(clientCtx client.Context, _ address.Codec) (clientv2keyring.Keyring, error) {
kb, err := client.NewKeyringFromBackend(clientCtx, clientCtx.Keyring.Backend())
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptio

// Setup initializes a new SimApp. A Nop logger is set in SimApp.
func Setup(t *testing.T, isCheckTx bool) *SimApp {
_ = isCheckTx
t.Helper()

privVal := mock.NewPV()
Expand Down
17 changes: 8 additions & 9 deletions x/collection/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"regexp"
"strings"

"cosmossdk.io/math"
"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/math"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
)

Expand All @@ -34,7 +35,7 @@ func DefaultNextClassIDs(contractID string) NextClassIDs {
}
}

func validateParams(params Params) error {
func validateParams(_ Params) error {
// limits are uint32, so no need to validate them.
return nil
}
Expand All @@ -43,7 +44,7 @@ type TokenClass interface {
proto.Message

GetId() string
SetId(ids *NextClassIDs)
SetID(ids *NextClassIDs)

SetName(name string)

Expand All @@ -55,12 +56,12 @@ type TokenClass interface {
func TokenClassToAny(class TokenClass) *codectypes.Any {
msg := class.(proto.Message)

any, err := codectypes.NewAnyWithValue(msg)
anyv, err := codectypes.NewAnyWithValue(msg)
if err != nil {
panic(err)
}

return any
return anyv
}

func TokenClassFromAny(any *codectypes.Any) TokenClass {
Expand All @@ -77,8 +78,7 @@ func TokenClassUnpackInterfaces(any *codectypes.Any, unpacker codectypes.AnyUnpa
// FTClass
var _ TokenClass = (*FTClass)(nil)

//lint:ignore var-naming
func (c *FTClass) SetId(ids *NextClassIDs) {
func (c *FTClass) SetID(ids *NextClassIDs) {
id := ids.Fungible
ids.Fungible = id.Incr()
c.Id = fmt.Sprintf("%08x", id.Uint64())
Expand Down Expand Up @@ -114,8 +114,7 @@ func (c FTClass) ValidateBasic() error {
// NFTClass
var _ TokenClass = (*NFTClass)(nil)

//lint:ignore var-naming
func (c *NFTClass) SetId(ids *NextClassIDs) {
func (c *NFTClass) SetID(ids *NextClassIDs) {
id := ids.NonFungible
ids.NonFungible = id.Incr()
c.Id = fmt.Sprintf("%08x", id.Uint64())
Expand Down
7 changes: 3 additions & 4 deletions x/collection/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ func TestFTClass(t *testing.T) {

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
var class collection.TokenClass
class = &collection.FTClass{
var class collection.TokenClass = &collection.FTClass{
Id: tc.id,
Decimals: tc.decimals,
}

if len(tc.id) == 0 {
class.SetId(&nextIDs)
class.SetID(&nextIDs)
}
class.SetName(tc.name)
class.SetMeta(tc.meta)
Expand Down Expand Up @@ -84,7 +83,7 @@ func TestNFTClass(t *testing.T) {
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
var class collection.TokenClass = &collection.NFTClass{}
class.SetId(&nextIDs)
class.SetID(&nextIDs)
class.SetName(tc.name)
class.SetMeta(tc.meta)

Expand Down
9 changes: 5 additions & 4 deletions x/collection/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math"

cmath "cosmossdk.io/math"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -51,8 +52,8 @@ func ValidateGenesis(data GenesisState) error {
return sdkerrors.ErrInvalidRequest.Wrap("classes cannot be empty")
}
for i := range contractClasses.Classes {
any := &contractClasses.Classes[i]
class := TokenClassFromAny(any)
anyv := &contractClasses.Classes[i]
class := TokenClassFromAny(anyv)
if err := class.ValidateBasic(); err != nil {
return err
}
Expand Down Expand Up @@ -228,8 +229,8 @@ func DefaultGenesisState() *GenesisState {
func (data GenesisState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
for _, contractClasses := range data.Classes {
for i := range contractClasses.Classes {
any := &contractClasses.Classes[i]
if err := TokenClassUnpackInterfaces(any, unpacker); err != nil {
anyv := &contractClasses.Classes[i]
if err := TokenClassUnpackInterfaces(anyv, unpacker); err != nil {
return err
}
}
Expand Down
3 changes: 2 additions & 1 deletion x/collection/keeper/alias.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package keeper

import (
gogotypes "github.com/cosmos/gogoproto/types"

"cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
gogotypes "github.com/cosmos/gogoproto/types"

"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
1 change: 1 addition & 0 deletions x/collection/keeper/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

cmath "cosmossdk.io/math"
"cosmossdk.io/store/prefix"

"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down
8 changes: 4 additions & 4 deletions x/collection/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *collection.GenesisState) {
contractID := contractClasses.ContractId

for i := range contractClasses.Classes {
any := &contractClasses.Classes[i]
class := collection.TokenClassFromAny(any)
anyv := &contractClasses.Classes[i]
class := collection.TokenClassFromAny(anyv)
k.setTokenClass(ctx, contractID, class)

// legacy
Expand Down Expand Up @@ -254,8 +254,8 @@ func (k Keeper) getClasses(ctx sdk.Context, contracts []collection.Contract) []c
}

k.iterateContractClasses(ctx, contractID, func(class collection.TokenClass) (stop bool) {
any := collection.TokenClassToAny(class)
contractClasses.Classes = append(contractClasses.Classes, *any)
anyv := collection.TokenClassToAny(class)
contractClasses.Classes = append(contractClasses.Classes, *anyv)
return false
})
if len(contractClasses.Classes) != 0 {
Expand Down
7 changes: 4 additions & 3 deletions x/collection/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package keeper
import (
"context"

"github.com/cosmos/gogoproto/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
"cosmossdk.io/store/prefix"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/gogoproto/proto"

"github.com/Finschia/finschia-sdk/x/collection"
)
Expand Down Expand Up @@ -426,12 +427,12 @@ func (s queryServer) Token(c context.Context, req *collection.QueryTokenRequest)
return nil, status.Error(codes.NotFound, err.Error())
}

any, err := codectypes.NewAnyWithValue(legacyToken)
anyv, err := codectypes.NewAnyWithValue(legacyToken)
if err != nil {
panic(err)
}

return &collection.QueryTokenResponse{Token: *any}, nil
return &collection.QueryTokenResponse{Token: *anyv}, nil
}

func (s queryServer) Root(c context.Context, req *collection.QueryRootRequest) (*collection.QueryRootResponse, error) {
Expand Down
4 changes: 3 additions & 1 deletion x/collection/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package keeper_test

import (
"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/gogoproto/proto"

"github.com/Finschia/finschia-sdk/x/collection"
)
Expand Down
1 change: 1 addition & 0 deletions x/collection/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"cosmossdk.io/log"
"cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
Expand Down
1 change: 1 addition & 0 deletions x/collection/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down
6 changes: 5 additions & 1 deletion x/collection/keeper/migrations/v3/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ package v3
import (
cmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/Finschia/finschia-sdk/x/collection"
)

// TODO: need to implement lggics for migrating ClassState and generate new genesis state for Collection
// TODO: need to implement logics for migrating ClassState and generate new genesis state for Collection
func MigrateStore(store, classStore storetypes.KVStore, cdc codec.BinaryCodec) error {
_, err := getClassState(classStore)
if err != nil {
return err
}

_ = store
_ = cdc

return nil
}

Expand Down
12 changes: 7 additions & 5 deletions x/collection/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package keeper
import (
"context"

"cosmossdk.io/math"
"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand Down Expand Up @@ -628,7 +629,7 @@ func (s msgServer) Modify(c context.Context, req *collection.MsgModify) (*collec
panic(err)
}

return s.keeper.ModifyNFT(ctx, req.ContractId, tokenID, operator, changes)
return s.keeper.ModifyNFT(ctx, req.ContractId, tokenID, changes)
}

event := collection.EventModifiedTokenClass{
Expand All @@ -642,7 +643,7 @@ func (s msgServer) Modify(c context.Context, req *collection.MsgModify) (*collec
panic(err)
}

return s.keeper.ModifyTokenClass(ctx, req.ContractId, classID, operator, changes)
return s.keeper.ModifyTokenClass(ctx, req.ContractId, classID, changes)
}

event := collection.EventModifiedTokenClass{
Expand All @@ -656,7 +657,7 @@ func (s msgServer) Modify(c context.Context, req *collection.MsgModify) (*collec
panic(err)
}

return s.keeper.ModifyTokenClass(ctx, req.ContractId, classID, operator, changes)
return s.keeper.ModifyTokenClass(ctx, req.ContractId, classID, changes)
}
if req.TokenIndex == "" {
event := collection.EventModifiedContract{
Expand All @@ -668,7 +669,8 @@ func (s msgServer) Modify(c context.Context, req *collection.MsgModify) (*collec
panic(err)
}

return s.keeper.ModifyContract(ctx, req.ContractId, operator, changes)
s.keeper.ModifyContract(ctx, req.ContractId, changes)
return nil
}

panic(sdkerrors.ErrInvalidRequest.Wrap("token index without type"))
Expand Down
4 changes: 3 additions & 1 deletion x/collection/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"encoding/json"
"fmt"

"cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"

Expand Down
Loading

0 comments on commit 7f34955

Please sign in to comment.