Skip to content

Ci/golangci lint v2 #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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@v7
if: steps.changed-go-files.outputs.any_changed == 'true'
with:
version: v1.61
version: v2.0

- name: Lint go code (gofumpt)
if: steps.changed-go-files.outputs.any_changed == 'true'
Expand Down
142 changes: 77 additions & 65 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
run:
timeout: 10m

version: "2"
linters:
disable-all: true
default: none
enable:
- asciicheck
- bidichk
Expand All @@ -17,17 +15,14 @@ linters:
- exhaustive
- forbidigo
- funlen
- gci
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- goimports
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
Expand All @@ -43,71 +38,88 @@ linters:
- promlinter
- revive
- staticcheck
- stylecheck
- tagliatelle
- tenv
- tparallel
- typecheck
- unconvert
- unparam
- unused
- wastedassign
- whitespace

linters-settings:
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- blank # blank imports
- dot # dot imports
- prefix(github.com/cometbft/cometbft) # comet
- prefix(cosmossdk.io) # cosmossdk.io
- prefix(github.com/cosmos/cosmos-sdk) # cosmos-sdk & cosmos org libs
- prefix(github.com/cosmos/interchain-security) # interchain-security
- prefix(github.com/cosmos/ibc-go) # ibc
- prefix(github.com/axone-protocol/axoned) # axone
custom-order: true

cyclop:
max-complexity: 20
skip-tests: true
funlen:
statements: 65
godot:
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

settings:
cyclop:
max-complexity: 20
funlen:
statements: 65
godot:
scope: declarations
lll:
line-length: 135
tagliatelle:
case:
rules:
json: snake
yaml: snake
use-field-name: true
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- lll
source: ^//\s*go:generate\s
- linters:
- godot
source: (noinspection|TODO)
- linters:
- gocritic
source: //noinspection
- linters:
- errorlint
source: ^\s+if _, ok := err\.\([^.]+\.InternalError\); ok {
- linters:
- dupl
- funlen
path: _test\.go
- linters:
- revive
path: _test\.go
text: "dot-imports:"
- linters:
- cyclop
path: (.+)_test\.go
paths:
- third_party$
- builtin$
- examples$
issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
- source: "^//\\s*go:generate\\s"
linters:
- lll
- source: "(noinspection|TODO)"
linters:
- godot
- source: "//noinspection"
linters:
- gocritic
- source: "^\\s+if _, ok := err\\.\\([^.]+\\.InternalError\\); ok {"
linters:
- errorlint
- path: "_test\\.go"
linters:
- dupl
- funlen
- path: "_test\\.go"
linters:
- revive
text: "dot-imports:"
uniq-by-line: false
formatters:
enable:
- gci
- goimports
settings:
gci:
sections:
- standard
- default
- blank
- dot
- prefix(github.com/cometbft/cometbft)
- prefix(cosmossdk.io)
- prefix(github.com/cosmos/cosmos-sdk)
- prefix(github.com/cosmos/interchain-security)
- prefix(github.com/cosmos/ibc-go)
- prefix(github.com/axone-protocol/axoned)
custom-order: true
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LEDGER_ENABLED ?= true

# Docker images
DOCKER_IMAGE_GOLANG = golang:1.23-alpine3.20
DOCKER_IMAGE_GOLANG_CI = golangci/golangci-lint:v1.61
DOCKER_IMAGE_GOLANG_CI = golangci/golangci-lint:v2.0
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
8 changes: 4 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.AccountKeeper.AddressCodec(),
)
app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper)
app.SetCircuitBreaker(&app.CircuitKeeper)

Check warning on line 444 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L444

Added line #L444 was not covered by tests

groupConfig := group.DefaultConfig()
/*
Expand Down Expand Up @@ -904,7 +904,7 @@
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
}
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
ctx := app.NewUncachedContext(true, tmproto.Header{})

Check warning on line 907 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L907

Added line #L907 was not covered by tests

// Initialize pinned codes in wasmvm as they are not persisted there
if err := app.WasmKeeper.InitializePinnedCodes(ctx); err != nil {
Expand Down Expand Up @@ -1136,15 +1136,15 @@

// RegisterTxService implements the Application.RegisterTxService method.
func (app *App) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
authtx.RegisterTxService(app.GRPCQueryRouter(), clientCtx, app.Simulate, app.interfaceRegistry)

Check warning on line 1139 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L1139

Added line #L1139 was not covered by tests
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *App) RegisterTendermintService(clientCtx client.Context) {
cmtApp := server.NewCometABCIWrapper(app)
cmtservice.RegisterTendermintService(
clientCtx,
app.BaseApp.GRPCQueryRouter(),
app.GRPCQueryRouter(),

Check warning on line 1147 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L1147

Added line #L1147 was not covered by tests
app.interfaceRegistry,
cmtApp.Query,
)
Expand Down
8 changes: 2 additions & 6 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
AppState: appState,
Validators: validators,
Height: height,
ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
ConsensusParams: app.GetConsensusParams(ctx),

Check warning on line 55 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L55

Added line #L55 was not covered by tests
}, nil
}

Expand All @@ -63,12 +63,8 @@
//
//nolint:funlen,gocognit,gocyclo,cyclop
func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false

// check if there is a allowed address list
if len(jailAllowedAddrs) > 0 {
applyAllowedAddrs = true
}
applyAllowedAddrs := len(jailAllowedAddrs) > 0

Check warning on line 67 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L67

Added line #L67 was not covered by tests

allowedAddrsMap := make(map[string]bool)

Expand Down
6 changes: 3 additions & 3 deletions x/logic/keeper/grpc_query_ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (

func (k Keeper) Ask(ctx goctx.Context, req *types.QueryServiceAskRequest) (response *types.QueryServiceAskResponse, err error) {
if req == nil {
return nil, errorsmod.Wrap(types.InvalidArgument, "request is nil")
return nil, errorsmod.Wrap(types.ErrInvalidArgument, "request is nil")
}

sdkCtx := withSafeGasMeter(sdk.UnwrapSDKContext(ctx))
defer func() {
if r := recover(); r != nil {
if gasError, ok := r.(storetypes.ErrorOutOfGas); ok {
response, err = nil, errorsmod.Wrapf(
types.LimitExceeded, "out of gas: %s <%s> (%d/%d)",
types.ErrLimitExceeded, "out of gas: %s <%s> (%d/%d)",
types.ModuleName, gasError.Descriptor, sdkCtx.GasMeter().GasConsumed(), sdkCtx.GasMeter().Limit())

return
Expand All @@ -49,7 +49,7 @@ func checkLimits(request *types.QueryServiceAskRequest, limits types.Limits) err
size := uint64(len(request.GetQuery()))

if limits.MaxSize != 0 && size > limits.MaxSize {
return errorsmod.Wrapf(types.LimitExceeded, "query: %d > MaxSize: %d", size, limits.MaxSize)
return errorsmod.Wrapf(types.ErrLimitExceeded, "query: %d > MaxSize: %d", size, limits.MaxSize)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions x/logic/keeper/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@

i, userOutput, err := k.newInterpreter(ctx, params)
if err != nil {
return nil, errorsmod.Wrapf(types.Internal, "error creating interpreter: %v", err.Error())
return nil, errorsmod.Wrapf(types.ErrInternal, "error creating interpreter: %v", err.Error())

Check warning on line 55 in x/logic/keeper/interpreter.go

View check run for this annotation

Codecov / codecov/patch

x/logic/keeper/interpreter.go#L55

Added line #L55 was not covered by tests
}
if err := i.ExecContext(ctx, program); err != nil {
return nil, errorsmod.Wrapf(types.InvalidArgument, "error compiling query: %v", err.Error())
return nil, errorsmod.Wrapf(types.ErrInvalidArgument, "error compiling query: %v", err.Error())
}

answer, err := k.queryInterpreter(ctx, i, query, calculateSolutionLimit(solutionsLimit, params.GetLimits().MaxResultCount))
Expand Down Expand Up @@ -183,7 +183,7 @@
switch rType := r.(type) {
case storetypes.ErrorOutOfGas:
err = errorsmod.Wrapf(
types.LimitExceeded, "out of gas: %s <%s> (%d/%d)",
types.ErrLimitExceeded, "out of gas: %s <%s> (%d/%d)",
types.ModuleName, rType.Descriptor, sdkctx.GasMeter().GasConsumed(), sdkctx.GasMeter().Limit())
default:
panic(r)
Expand Down
6 changes: 3 additions & 3 deletions x/logic/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
)

var (
InvalidArgument = sdkerrors.RegisterWithGRPCCode(ModuleName, 1, codes.InvalidArgument, "invalid argument")
ErrInvalidArgument = sdkerrors.RegisterWithGRPCCode(ModuleName, 1, codes.InvalidArgument, "invalid argument")
// LimitExceeded is returned when a limit is exceeded.
LimitExceeded = sdkerrors.RegisterWithGRPCCode(ModuleName, 2, codes.InvalidArgument, "limit exceeded")
ErrLimitExceeded = sdkerrors.RegisterWithGRPCCode(ModuleName, 2, codes.InvalidArgument, "limit exceeded")
// Internal is returned when an internal error occurs.
Internal = sdkerrors.RegisterWithGRPCCode(ModuleName, 3, codes.Internal, "internal error")
ErrInternal = sdkerrors.RegisterWithGRPCCode(ModuleName, 3, codes.Internal, "internal error")
)
10 changes: 5 additions & 5 deletions x/logic/util/prolog.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
p := engine.NewParser(&i.VM, strings.NewReader(query))
t, err := p.Term()
if err != nil {
return nil, errorsmod.Wrapf(types.InvalidArgument, "error executing query: %v", err.Error())
return nil, errorsmod.Wrapf(types.ErrInvalidArgument, "error executing query: %v", err.Error())

Check warning on line 38 in x/logic/util/prolog.go

View check run for this annotation

Codecov / codecov/patch

x/logic/util/prolog.go#L38

Added line #L38 was not covered by tests
}

var env *engine.Env
Expand All @@ -52,20 +52,20 @@
vars := parsedVarsToVars(p.Vars)
results, err := envsToResults(envs, p.Vars, i)
if err != nil {
return nil, errorsmod.Wrapf(types.InvalidArgument, "error executing query: %v", err.Error())
return nil, errorsmod.Wrapf(types.ErrInvalidArgument, "error executing query: %v", err.Error())

Check warning on line 55 in x/logic/util/prolog.go

View check run for this annotation

Codecov / codecov/patch

x/logic/util/prolog.go#L55

Added line #L55 was not covered by tests
}

if callErr != nil {
if uint64(len(results)) < solutionsLimit {
// error is not part of the look-ahead and should be included in the solutions
if errors.Is(callErr, types.LimitExceeded) {
if errors.Is(callErr, types.ErrLimitExceeded) {

Check warning on line 61 in x/logic/util/prolog.go

View check run for this annotation

Codecov / codecov/patch

x/logic/util/prolog.go#L61

Added line #L61 was not covered by tests
return nil, callErr
}

var err engine.Exception
if errors.As(callErr, &err) {
if err, ok := isPanicError(err.Term()); ok {
return nil, errorsmod.Wrapf(types.LimitExceeded, "%s", err)
return nil, errorsmod.Wrapf(types.ErrLimitExceeded, "%s", err)

Check warning on line 68 in x/logic/util/prolog.go

View check run for this annotation

Codecov / codecov/patch

x/logic/util/prolog.go#L68

Added line #L68 was not covered by tests
}
}

Expand All @@ -76,7 +76,7 @@
sdkCtx := sdk.UnwrapSDKContext(ctx)
if sdkCtx.GasMeter().IsOutOfGas() {
return errorsmod.Wrapf(
types.LimitExceeded, "out of gas: %s <%s> (%d/%d)",
types.ErrLimitExceeded, "out of gas: %s <%s> (%d/%d)",

Check warning on line 79 in x/logic/util/prolog.go

View check run for this annotation

Codecov / codecov/patch

x/logic/util/prolog.go#L79

Added line #L79 was not covered by tests
types.ModuleName, callErr.Error(), sdkCtx.GasMeter().GasConsumed(), sdkCtx.GasMeter().Limit())
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion x/mint/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) {
), &accountKeeper)
require.NoError(t, err)

ctx := app.BaseApp.NewContext(false)
ctx := app.NewContext(false)
acc := accountKeeper.GetAccount(ctx, authtypes.NewModuleAddress(types.ModuleName))
require.NotNil(t, acc)
}
Loading
Loading