Skip to content

Commit

Permalink
Merge pull request #566 from okp4/style/enforce-style
Browse files Browse the repository at this point in the history
Style/enforce style
  • Loading branch information
ccamel committed Feb 22, 2024
2 parents d7f5b20 + 60e72da commit ad04ce4
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
37 changes: 22 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +27,9 @@ linters:
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- makezero
- nakedret
Expand All @@ -45,11 +42,16 @@ linters:
- predeclared
- promlinter
- revive
- staticcheck
- stylecheck
- tagliatelle
- tenv
- tparallel
- typecheck
- unconvert
- unparam
- unused
- wastedassign
- whitespace

linters-settings:
Expand All @@ -76,6 +78,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

Expand All @@ -86,21 +94,20 @@ 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 {"
linters:
- errorlint
- path: "_test\\.go"
linters:
- bodyclose
- dupl
- funlen
- goconst
- noctx
- unused
- wrapcheck
- path: "_test\\.go"
linters:
- revive
text: "dot-imports:"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions scripts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
},
Expand All @@ -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()
},
}
Expand All @@ -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()
},
}
Expand Down
2 changes: 1 addition & 1 deletion x/logic/keeper/grpc_query_ask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
)
Expand Down
2 changes: 1 addition & 1 deletion x/logic/keeper/grpc_query_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
)
Expand Down
2 changes: 1 addition & 1 deletion x/logic/keeper/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion x/logic/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
)
Expand Down
4 changes: 2 additions & 2 deletions x/logic/predicate/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions x/logic/predicate/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down Expand Up @@ -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)
})
}
Expand Down Expand Up @@ -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)),
Expand Down
2 changes: 1 addition & 1 deletion x/logic/predicate/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/logic/predicate/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions x/logic/predicate/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ 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
}
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
Expand Down
2 changes: 1 addition & 1 deletion x/logic/testutil/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}))
Expand Down
6 changes: 3 additions & 3 deletions x/mint/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions x/vesting/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions x/vesting/types/vesting_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ad04ce4

Please sign in to comment.