Skip to content
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

Chore/upgrade golangci-lint to 1.61 #776

Merged
merged 7 commits into from
Oct 8, 2024
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@v6
if: steps.changed-go-files.outputs.any_changed == 'true'
with:
version: v1.56
version: v1.61

- name: Lint go code (gofumpt)
if: steps.changed-go-files.outputs.any_changed == 'true'
Expand Down
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.56
DOCKER_IMAGE_GOLANG_CI = golangci/golangci-lint:v1.61
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
2 changes: 1 addition & 1 deletion x/logic/keeper/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func whenTheQueryIsRun(ctx context.Context) error {
func whenTheQueryIsRunLimitedToNSolutions(ctx context.Context, n int) error {
request := testCaseFromContext(ctx).request

limit := sdkmath.NewUint(uint64(n))
limit := sdkmath.NewUint(uint64(n)) //nolint:gosec // disable G115
request.Limit = &limit

testCaseFromContext(ctx).request = request
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 @@ -446,7 +446,7 @@ func TestGRPCAsk(t *testing.T) {

var limit *sdkmath.Uint
if tc.limit != 0 {
v := sdkmath.NewUint(uint64(tc.limit))
v := sdkmath.NewUint(uint64(tc.limit)) //nolint:gosec // disable G115
limit = &v
}
query := types.QueryServiceAskRequest{
Expand Down
4 changes: 2 additions & 2 deletions x/logic/keeper/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (k Keeper) execute(
}

return &types.QueryServiceAskResponse{
Height: uint64(sdkCtx.BlockHeight()),
Height: uint64(sdkCtx.BlockHeight()), //nolint:gosec // disable G115
GasUsed: sdkCtx.GasMeter().GasConsumed(),
Answer: answer,
UserOutput: userOutput.String(),
Expand Down Expand Up @@ -97,7 +97,7 @@ func (k Keeper) newInterpreter(ctx context.Context, params types.Params) (*prolo
var userOutputBuffer writerStringer
limits := params.GetLimits()
if limits.MaxUserOutputSize != nil && limits.MaxUserOutputSize.GT(sdkmath.ZeroUint()) {
userOutputBuffer = util.NewBoundedBufferMust(int(limits.MaxUserOutputSize.Uint64()))
userOutputBuffer = util.NewBoundedBufferMust(int(limits.MaxUserOutputSize.Uint64())) //nolint:gosec // disable G115
} else {
userOutputBuffer = new(strings.Builder)
}
Expand Down
6 changes: 3 additions & 3 deletions x/logic/predicate/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func ReadString(vm *engine.VM, stream, length, result engine.Term, cont engine.C

var maxLength uint64
if maxLen, ok := env.Resolve(length).(engine.Integer); ok {
maxLength = uint64(maxLen)
maxLength = uint64(maxLen) //nolint:gosec // disable G115
}

var builder strings.Builder
Expand All @@ -63,7 +63,7 @@ func ReadString(vm *engine.VM, stream, length, result engine.Term, cont engine.C
}
return engine.Error(engine.SyntaxError(prolog.ErrorTerm(err), env))
}
totalLen += uint64(l)
totalLen += uint64(l) //nolint:gosec // disable G115
_, err = builder.WriteRune(r)
if err != nil {
return engine.Error(engine.SyntaxError(prolog.ErrorTerm(err), env))
Expand All @@ -73,7 +73,7 @@ func ReadString(vm *engine.VM, stream, length, result engine.Term, cont engine.C
var r engine.Term = engine.NewAtom(builder.String())
return engine.Unify(
vm, prolog.Tuple(result, length),
prolog.Tuple(r, engine.Integer(totalLen)), cont, env)
prolog.Tuple(r, engine.Integer(totalLen)), cont, env) //nolint:gosec // disable G115
}

// StringBytes is a predicate that unifies a string with a list of bytes, returning true when the (Unicode) String is
Expand Down
1 change: 1 addition & 0 deletions x/logic/prolog/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// If no option is found nil is returned.
func GetOption(name engine.Atom, options engine.Term, env *engine.Env) (engine.Term, error) {
extractOption := func(opt engine.Term) (engine.Term, error) {
//nolint:nilnil
switch v := env.Resolve(opt).(type) {
case engine.Compound:
if v.Functor() == name {
Expand Down
4 changes: 2 additions & 2 deletions x/logic/testutil/keeper_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func MockAuthQueryServiceWithAddresses(mock *MockAuthQueryService, addresses []s
start = fromCursor(req.Pagination.Key)
}
if req.Pagination.Limit != 0 {
limit = int(req.Pagination.GetLimit())
limit = int(req.Pagination.GetLimit()) //nolint:gosec // disable G115
}
}
accounts := lo.Map(
Expand Down Expand Up @@ -67,7 +67,7 @@ func MockAuthQueryServiceWithAddresses(mock *MockAuthQueryService, addresses []s
Accounts: accounts,
Pagination: &query.PageResponse{
NextKey: lo.If(start+limit < total, toCursor(start+1)).Else(nil),
Total: uint64(total),
Total: uint64(total), //nolint:gosec // disable G115
},
}, nil
})
Expand Down
2 changes: 1 addition & 1 deletion x/logic/util/prolog.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

var panicErr engine.PanicError
if errors.As(callErr, &panicErr) && errors.Is(panicErr.OriginErr, engine.ErrMaxVariables) {
return nil, errorsmod.Wrapf(types.LimitExceeded, panicErr.OriginErr.Error())
return nil, errorsmod.Wrapf(types.LimitExceeded, panicErr.OriginErr.Error()) //nolint:govet

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

View check run for this annotation

Codecov / codecov/patch

x/logic/util/prolog.go#L62

Added line #L62 was not covered by tests
}

if err = func() error {
Expand Down
2 changes: 1 addition & 1 deletion x/mint/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account)
var authority sdk.AccAddress = address.Module("gov")

params := types.DefaultParams()
params.BlocksPerYear = uint64(simtypes.RandIntBetween(r, 1, 1000000))
params.BlocksPerYear = uint64(simtypes.RandIntBetween(r, 1, 1000000)) //nolint:gosec // disable G115
params.InflationCoef = math.LegacyNewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2)
params.MintDenom = simtypes.RandStringOfLength(r, 10)

Expand Down
12 changes: 6 additions & 6 deletions x/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ func validateInflationCoef(i interface{}) error {
return nil
}

func validateBounds(min, max interface{}) error {
vmin, ok := min.(*math.LegacyDec)
func validateBounds(minBound, maxBound interface{}) error {
vmin, ok := minBound.(*math.LegacyDec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", min)
return fmt.Errorf("invalid parameter type: %T", minBound)
}
vmax, ok := max.(*math.LegacyDec)
vmax, ok := maxBound.(*math.LegacyDec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", max)
return fmt.Errorf("invalid parameter type: %T", maxBound)
}

for _, v := range []*math.LegacyDec{vmin, vmax} {
Expand All @@ -104,7 +104,7 @@ func validateBounds(min, max interface{}) error {
}

if vmin != nil && vmax != nil && vmin.GT(*vmax) {
return fmt.Errorf("inflation min cannot greater than inflation max")
return fmt.Errorf("inflation min cannot be greater than inflation max")
}

return nil
Expand Down
89 changes: 89 additions & 0 deletions x/mint/types/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package types

import (
"fmt"
"testing"

. "github.com/smartystreets/goconvey/convey"

"cosmossdk.io/math"
)

func toLegacyDec(i int64) *math.LegacyDec {
ii := math.LegacyNewDec(i)
return &ii
}

func Test_validateBounds(t *testing.T) {
Convey("Given test cases", t, func() {
cases := []struct {
name string
minBound, maxBound interface{}
expectErr bool
err error
}{
{
name: "validate bounds types",
minBound: toLegacyDec(2),
maxBound: toLegacyDec(99999999),
expectErr: false,
err: nil,
},
{
name: "validate invalid min type",
minBound: 2,
maxBound: toLegacyDec(99999999),
expectErr: true,
err: func() error {
return fmt.Errorf("invalid parameter type: %T", 2)
}(),
},
{
name: "validate invalid max type",
minBound: toLegacyDec(0),
maxBound: 999999.0,
expectErr: true,
err: func() error {
return fmt.Errorf("invalid parameter type: %T", 999999.0)
}(),
},
{
name: "validate non-negative bounds",
minBound: toLegacyDec(-2),
maxBound: toLegacyDec(99999999),
expectErr: true,
err: func() error {
return fmt.Errorf("inflation bound cannot be negative: %s", toLegacyDec(-2))
}(),
},
{
name: "validate non-negative bounds",
minBound: toLegacyDec(99999999),
maxBound: toLegacyDec(1),
expectErr: true,
err: func() error {
return fmt.Errorf("inflation min cannot be greater than inflation max")
}(),
},
}
for nc, tc := range cases {
Convey(
fmt.Sprintf("Given test case #%d: %v, with params: %v, %v", nc, tc.name, tc.minBound, tc.maxBound), func() {
Convey("when validate bounds", func() {
err := validateBounds(tc.minBound, tc.maxBound)

if tc.expectErr {
Convey("then bounds validation expect error", func() {
So(err, ShouldNotBeNil)
So(err, ShouldResemble, tc.err)
})
} else {
Convey("then error should be nil", func() {
So(err, ShouldBeNil)
})
}
})
})
}
})
}
Loading