From f8dcdf211bec2551e8e175c27954bac7b888b482 Mon Sep 17 00:00:00 2001 From: ccamel Date: Wed, 21 Feb 2024 17:43:19 +0100 Subject: [PATCH 1/4] build(deps): bump golangci/golangci-lint from v1.54 to v1.56 --- .github/workflows/lint.yml | 2 +- .golangci.yml | 25 ++++++++++++------------- Makefile | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 234b551a..e476c71f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -106,7 +106,7 @@ jobs: uses: golangci/golangci-lint-action@v4 if: steps.changed-go-files.outputs.any_changed == 'true' with: - version: v1.54 + version: v1.56 - name: Lint go code (gofumpt) if: steps.changed-go-files.outputs.any_changed == 'true' diff --git a/.golangci.yml b/.golangci.yml index 52671e61..dfb13738 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,25 +4,19 @@ run: linters: disable-all: true enable: - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - typecheck - - unused - asciicheck - bidichk - bodyclose - cyclop - dupl - durationcheck + - errcheck - errname - errorlint - exhaustive - exportloopref - - funlen - forbidigo + - funlen - gci - gocognit - goconst @@ -33,6 +27,9 @@ linters: - gomodguard - goprintffuncname - gosec + - gosimple + - govet + - ineffassign - lll - makezero - nakedret @@ -45,11 +42,14 @@ linters: - predeclared - promlinter - revive + - staticcheck - stylecheck - tenv - tparallel + - typecheck - unconvert - unparam + - unused - whitespace linters-settings: @@ -97,10 +97,9 @@ issues: - errorlint - path: "_test\\.go" linters: - - bodyclose - dupl - funlen - - goconst - - noctx - - unused - - wrapcheck + - path: "_test\\.go" + linters: + - revive + text: "dot-imports:" diff --git a/Makefile b/Makefile index ef2ee753..ec6aa471 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ LEDGER_ENABLED ?= true # Docker images DOCKER_IMAGE_GOLANG = golang:1.21-alpine3.17 -DOCKER_IMAGE_GOLANG_CI = golangci/golangci-lint:v1.54 +DOCKER_IMAGE_GOLANG_CI = golangci/golangci-lint:v1.56 DOCKER_IMAGE_PROTO = ghcr.io/cosmos/proto-builder:0.14.0 DOCKER_IMAGE_BUF = bufbuild/buf:1.4.0 DOCKER_PROTO_RUN := docker run --rm --user $(id -u):$(id -g) -v $(HOME)/.cache:/root/.cache -v $(PWD):/workspace --workdir /workspace $(DOCKER_IMAGE_PROTO) From 8612b73799b7ccffb5161b35215b33bf1e175be8 Mon Sep 17 00:00:00 2001 From: ccamel Date: Wed, 21 Feb 2024 17:45:07 +0100 Subject: [PATCH 2/4] build(project): add tagliatelle linter --- .golangci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index dfb13738..a8a82a42 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -44,6 +44,7 @@ linters: - revive - staticcheck - stylecheck + - tagliatelle - tenv - tparallel - typecheck @@ -76,6 +77,12 @@ linters-settings: scope: declarations # comments to be checked: `declarations` (default), `toplevel`, or `all` lll: line-length: 135 + tagliatelle: + case: + use-field-name: true + rules: + json: snake + yaml: snake output: uniq-by-line: false From 9ceeaa57c4ca7a04b2b8a5cfd0a102cdf2e852fa Mon Sep 17 00:00:00 2001 From: ccamel Date: Wed, 21 Feb 2024 17:46:18 +0100 Subject: [PATCH 3/4] build(project): add whitespace --- .golangci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a8a82a42..a6b4cc4f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -51,6 +51,7 @@ linters: - unconvert - unparam - unused + - wastedassign - whitespace linters-settings: @@ -93,10 +94,10 @@ issues: - source: "^//\\s*go:generate\\s" linters: - lll - - source: '(noinspection|TODO)' + - source: "(noinspection|TODO)" linters: - godot - - source: '//noinspection' + - source: "//noinspection" linters: - gocritic - source: "^\\s+if _, ok := err\\.\\([^.]+\\.InternalError\\); ok {" From 60e72da973da0a487b212858de3e18b7dbd27e32 Mon Sep 17 00:00:00 2001 From: ccamel Date: Wed, 21 Feb 2024 17:54:20 +0100 Subject: [PATCH 4/4] style: improve code style following linter rules enforcement --- scripts/main.go | 6 +++--- x/logic/keeper/grpc_query_ask_test.go | 2 +- x/logic/keeper/grpc_query_params_test.go | 2 +- x/logic/keeper/interpreter.go | 2 +- x/logic/keeper/msg_server_test.go | 2 +- x/logic/predicate/address.go | 4 ++-- x/logic/predicate/bank.go | 6 +++--- x/logic/predicate/file.go | 2 +- x/logic/predicate/string.go | 4 ++-- x/logic/predicate/uri.go | 4 ++-- x/logic/testutil/logic.go | 2 +- x/mint/client/cli/query.go | 6 +++--- x/vesting/client/cli/tx.go | 10 +++++----- x/vesting/types/vesting_account.go | 10 +++++----- 14 files changed, 31 insertions(+), 31 deletions(-) diff --git a/scripts/main.go b/scripts/main.go index a8c1cf7f..270718c9 100644 --- a/scripts/main.go +++ b/scripts/main.go @@ -12,7 +12,7 @@ func main() { rootCmd := &cobra.Command{ Use: "gendoc", Short: "Simple CLI to generate documentation for the project", - PersistentPreRun: func(cmd *cobra.Command, args []string) { + PersistentPreRun: func(cmd *cobra.Command, _ []string) { cmd.SetOut(cmd.OutOrStdout()) cmd.SetErr(cmd.ErrOrStderr()) }, @@ -31,7 +31,7 @@ func generateCommandDocumentationCommand() *cobra.Command { cmd := &cobra.Command{ Use: "command", Short: "Generate command documentation", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { return GenerateCommandDocumentation() }, } @@ -42,7 +42,7 @@ func generatePredicateDocumentationCommand() *cobra.Command { cmd := &cobra.Command{ Use: "predicate", Short: "Generate predicate documentation", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { return GeneratePredicateDocumentation() }, } diff --git a/x/logic/keeper/grpc_query_ask_test.go b/x/logic/keeper/grpc_query_ask_test.go index 26b47be4..0ca7f650 100644 --- a/x/logic/keeper/grpc_query_ask_test.go +++ b/x/logic/keeper/grpc_query_ask_test.go @@ -211,7 +211,7 @@ func TestGRPCAsk(t *testing.T) { authtypes.NewModuleAddress(govtypes.ModuleName), accountKeeper, bankKeeper, - func(ctx gocontext.Context) fs.FS { + func(_ gocontext.Context) fs.FS { return fsProvider }, ) diff --git a/x/logic/keeper/grpc_query_params_test.go b/x/logic/keeper/grpc_query_params_test.go index 75020b85..4ec9d25f 100644 --- a/x/logic/keeper/grpc_query_params_test.go +++ b/x/logic/keeper/grpc_query_params_test.go @@ -69,7 +69,7 @@ func TestGRPCParams(t *testing.T) { authtypes.NewModuleAddress(govtypes.ModuleName), accountKeeper, bankKeeper, - func(ctx gocontext.Context) fs.FS { + func(_ gocontext.Context) fs.FS { return fsProvider }, ) diff --git a/x/logic/keeper/interpreter.go b/x/logic/keeper/interpreter.go index 4d95349e..641cbd71 100644 --- a/x/logic/keeper/interpreter.go +++ b/x/logic/keeper/interpreter.go @@ -130,7 +130,7 @@ func (k Keeper) newInterpreter(ctx context.Context) (*prolog.Interpreter, *util. toPredicate( nonNilNorZeroOrDefaultUint64(gasPolicy.DefaultPredicateCost, defaultPredicateCost), gasPolicy.GetPredicateCosts())), - func(agg interpreter.Predicates, item lo.Tuple2[string, uint64], index int) interpreter.Predicates { + func(agg interpreter.Predicates, item lo.Tuple2[string, uint64], _ int) interpreter.Predicates { agg[item.A] = item.B return agg }, diff --git a/x/logic/keeper/msg_server_test.go b/x/logic/keeper/msg_server_test.go index ac34db84..5d90238b 100644 --- a/x/logic/keeper/msg_server_test.go +++ b/x/logic/keeper/msg_server_test.go @@ -67,7 +67,7 @@ func TestUpdateParams(t *testing.T) { authtypes.NewModuleAddress(govtypes.ModuleName), accountKeeper, bankKeeper, - func(ctx gocontext.Context) fs.FS { + func(_ gocontext.Context) fs.FS { return fsProvider }, ) diff --git a/x/logic/predicate/address.go b/x/logic/predicate/address.go index 3318c141..4f9a30e3 100644 --- a/x/logic/predicate/address.go +++ b/x/logic/predicate/address.go @@ -34,7 +34,7 @@ import ( // [bech32]: https://docs.cosmos.network/main/build/spec/addresses/bech32#hrp-table // [base64]: https://fr.wikipedia.org/wiki/Base64 func Bech32Address(_ *engine.VM, address, bech32 engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise { - forwardConverter := func(value []engine.Term, options engine.Term, env *engine.Env) ([]engine.Term, error) { + forwardConverter := func(value []engine.Term, _ engine.Term, env *engine.Env) ([]engine.Term, error) { hrpTerm, dataTerm, err := prolog.AssertPair(env, value[0]) if err != nil { return nil, err @@ -55,7 +55,7 @@ func Bech32Address(_ *engine.VM, address, bech32 engine.Term, cont engine.Cont, return []engine.Term{engine.NewAtom(b)}, nil } - backwardConverter := func(value []engine.Term, options engine.Term, env *engine.Env) ([]engine.Term, error) { + backwardConverter := func(value []engine.Term, _ engine.Term, env *engine.Env) ([]engine.Term, error) { b, err := prolog.AssertAtom(env, value[0]) if err != nil { return nil, err diff --git a/x/logic/predicate/bank.go b/x/logic/predicate/bank.go index 8cccfc33..3db2f13e 100644 --- a/x/logic/predicate/bank.go +++ b/x/logic/predicate/bank.go @@ -73,7 +73,7 @@ func BankSpendableBalances(vm *engine.VM, account, balances engine.Term, cont en vm, env, cont, - func(ctx sdk.Context, bankKeeper types.BankKeeper, coins sdk.Coins, address sdk.AccAddress) sdk.Coins { + func(ctx sdk.Context, bankKeeper types.BankKeeper, _ sdk.Coins, address sdk.AccAddress) sdk.Coins { return SpendableCoinsSorted(ctx, bankKeeper, address) }) } @@ -105,7 +105,7 @@ func BankLockedBalances(vm *engine.VM, account, balances engine.Term, cont engin vm, env, cont, - func(ctx sdk.Context, bankKeeper types.BankKeeper, coins sdk.Coins, address sdk.AccAddress) sdk.Coins { + func(ctx sdk.Context, bankKeeper types.BankKeeper, _ sdk.Coins, address sdk.AccAddress) sdk.Coins { return LockedCoinsSorted(ctx, bankKeeper, address) }) } @@ -161,7 +161,7 @@ func fetchBalances( promises = append( promises, - func(ctx context.Context) *engine.Promise { + func(_ context.Context) *engine.Promise { return engine.Unify( vm, prolog.Tuple(engine.NewAtom(address), CoinsToTerm(coins)), diff --git a/x/logic/predicate/file.go b/x/logic/predicate/file.go index a4a344e0..e24ffc98 100644 --- a/x/logic/predicate/file.go +++ b/x/logic/predicate/file.go @@ -38,7 +38,7 @@ func SourceFile(vm *engine.VM, file engine.Term, cont engine.Cont, env *engine.E term := engine.NewAtom(sortedSource[i]) promises = append( promises, - func(ctx context.Context) *engine.Promise { + func(_ context.Context) *engine.Promise { return engine.Unify( vm, file, diff --git a/x/logic/predicate/string.go b/x/logic/predicate/string.go index dc811eee..727376fb 100644 --- a/x/logic/predicate/string.go +++ b/x/logic/predicate/string.go @@ -110,7 +110,7 @@ func StringBytes( if err != nil { return engine.Error(err) } - forwardConverter := func(value []engine.Term, options engine.Term, env *engine.Env) ([]engine.Term, error) { + forwardConverter := func(value []engine.Term, _ engine.Term, env *engine.Env) ([]engine.Term, error) { str, err := prolog.TextTermToString(value[0], env) if err != nil { return nil, err @@ -134,7 +134,7 @@ func StringBytes( return []engine.Term{prolog.BytesToByteListTerm(bs)}, nil } } - backwardConverter := func(value []engine.Term, options engine.Term, env *engine.Env) ([]engine.Term, error) { + backwardConverter := func(value []engine.Term, _ engine.Term, env *engine.Env) ([]engine.Term, error) { var result string switch encoding { case prolog.AtomText: diff --git a/x/logic/predicate/uri.go b/x/logic/predicate/uri.go index a53907d3..68d7e0a6 100644 --- a/x/logic/predicate/uri.go +++ b/x/logic/predicate/uri.go @@ -39,7 +39,7 @@ func URIEncoded(_ *engine.VM, component, decoded, encoded engine.Term, cont engi if err != nil { return engine.Error(err) } - forwardConverter := func(value []engine.Term, options engine.Term, env *engine.Env) ([]engine.Term, error) { + forwardConverter := func(value []engine.Term, _ engine.Term, env *engine.Env) ([]engine.Term, error) { in, err := prolog.TextTermToString(value[0], env) if err != nil { return nil, err @@ -47,7 +47,7 @@ func URIEncoded(_ *engine.VM, component, decoded, encoded engine.Term, cont engi out := uriComponent.Escape(in) return []engine.Term{engine.NewAtom(out)}, nil } - backwardConverter := func(value []engine.Term, options engine.Term, env *engine.Env) ([]engine.Term, error) { + backwardConverter := func(value []engine.Term, _ engine.Term, env *engine.Env) ([]engine.Term, error) { in, err := prolog.TextTermToString(value[0], env) if err != nil { return nil, err diff --git a/x/logic/testutil/logic.go b/x/logic/testutil/logic.go index 3418de11..f83aeb01 100644 --- a/x/logic/testutil/logic.go +++ b/x/logic/testutil/logic.go @@ -84,7 +84,7 @@ func CompileMust(ctx context.Context, i *prolog.Interpreter, s string, args ...i func ReindexUnknownVariables(s prolog.TermString) prolog.TermString { re := regexp.MustCompile("_([0-9]+)") var index int - return prolog.TermString(re.ReplaceAllStringFunc(string(s), func(m string) string { + return prolog.TermString(re.ReplaceAllStringFunc(string(s), func(_ string) string { index++ return fmt.Sprintf("_%d", index) })) diff --git a/x/mint/client/cli/query.go b/x/mint/client/cli/query.go index 6b07308c..1352f5b1 100644 --- a/x/mint/client/cli/query.go +++ b/x/mint/client/cli/query.go @@ -37,7 +37,7 @@ func GetCmdQueryParams() *cobra.Command { Use: "params", Short: "Query the current minting parameters", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err @@ -66,7 +66,7 @@ func GetCmdQueryInflation() *cobra.Command { Use: "inflation", Short: "Query the current minting inflation value", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err @@ -95,7 +95,7 @@ func GetCmdQueryAnnualProvisions() *cobra.Command { Use: "annual-provisions", Short: "Query the current minting annual provisions value", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err diff --git a/x/vesting/client/cli/tx.go b/x/vesting/client/cli/tx.go index 5f589605..61be654c 100644 --- a/x/vesting/client/cli/tx.go +++ b/x/vesting/client/cli/tx.go @@ -129,8 +129,8 @@ type VestingData struct { } type InputPeriod struct { - Coins string `json:"coins"` - Length int64 `json:"length_seconds"` + Coins string `json:"coins"` + LengthSeconds int64 `json:"length_seconds"` } // NewMsgCreatePeriodicVestingAccountCmd returns a CLI command handler for creating a @@ -190,10 +190,10 @@ func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command { return err } - if p.Length < 0 { - return fmt.Errorf("invalid period length of %d in period %d, length must be greater than 0", p.Length, i) + if p.LengthSeconds < 0 { + return fmt.Errorf("invalid period length of %d in period %d, length must be greater than 0", p.LengthSeconds, i) } - period := types.Period{Length: p.Length, Amount: amount} + period := types.Period{Length: p.LengthSeconds, Amount: amount} periods = append(periods, period) } diff --git a/x/vesting/types/vesting_account.go b/x/vesting/types/vesting_account.go index bdded34b..64cd4de8 100644 --- a/x/vesting/types/vesting_account.go +++ b/x/vesting/types/vesting_account.go @@ -157,7 +157,7 @@ func (bva BaseVestingAccount) Validate() error { type vestingAccountYAML struct { Address sdk.AccAddress `json:"address"` - PubKey string `json:"public_key"` + PublicKey string `json:"public_key"` AccountNumber uint64 `json:"account_number"` Sequence uint64 `json:"sequence"` OriginalVesting sdk.Coins `json:"original_vesting"` @@ -186,7 +186,7 @@ func (bva BaseVestingAccount) MarshalYAML() (interface{}, error) { out := vestingAccountYAML{ Address: accAddr, AccountNumber: bva.AccountNumber, - PubKey: getPKString(bva), + PublicKey: getPKString(bva), Sequence: bva.Sequence, OriginalVesting: bva.OriginalVesting, DelegatedFree: bva.DelegatedFree, @@ -304,7 +304,7 @@ func (cva ContinuousVestingAccount) MarshalYAML() (interface{}, error) { out := vestingAccountYAML{ Address: accAddr, AccountNumber: cva.AccountNumber, - PubKey: getPKString(cva), + PublicKey: getPKString(cva), Sequence: cva.Sequence, OriginalVesting: cva.OriginalVesting, DelegatedFree: cva.DelegatedFree, @@ -453,7 +453,7 @@ func (pva PeriodicVestingAccount) MarshalYAML() (interface{}, error) { out := vestingAccountYAML{ Address: accAddr, AccountNumber: pva.AccountNumber, - PubKey: getPKString(pva), + PublicKey: getPKString(pva), Sequence: pva.Sequence, OriginalVesting: pva.OriginalVesting, DelegatedFree: pva.DelegatedFree, @@ -725,7 +725,7 @@ func (cva CliffVestingAccount) MarshalYAML() (interface{}, error) { out := vestingAccountYAML{ Address: accAddr, AccountNumber: cva.AccountNumber, - PubKey: getPKString(cva), + PublicKey: getPKString(cva), Sequence: cva.Sequence, OriginalVesting: cva.OriginalVesting, DelegatedFree: cva.DelegatedFree,