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

fix: bump golangci lint to 1.62 #3278

Merged
merged 9 commits into from
Dec 6, 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
1 change: 1 addition & 0 deletions .github/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ linters-settings:
excludes:
- G204 # Subprocess launched with a potential tainted input or cmd arguments
- G306 # Expect WriteFile permissions to be 0600 or less
- G115 # Integer overflow conversion, no solution to check the overflow in time of convert, so linter shouldn't check the overflow.
stylecheck:
checks: [ "all", "-ST1022", "-ST1003" ]
errorlint:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
working-directory: ${{ inputs.modulepath }}
args:
--config=${{ github.workspace }}/.github/golangci.yml
version: v1.59 # sync with misc/devdeps
version: v1.62 # sync with misc/devdeps
6 changes: 3 additions & 3 deletions gno.land/pkg/gnoclient/client_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *Client) Query(cfg QueryCfg) (*ctypes.ResultABCIQuery, error) {
}

if qres.Response.Error != nil {
return qres, errors.Wrap(qres.Response.Error, "deliver transaction failed: log:%s", qres.Response.Log)
return qres, errors.Wrapf(qres.Response.Error, "deliver transaction failed: log:%s", qres.Response.Log)
}

return qres, nil
Expand Down Expand Up @@ -97,7 +97,7 @@ func (c *Client) Render(pkgPath string, args string) (string, *ctypes.ResultABCI
return "", nil, errors.Wrap(err, "query render")
}
if qres.Response.Error != nil {
return "", nil, errors.Wrap(qres.Response.Error, "Render failed: log:%s", qres.Response.Log)
return "", nil, errors.Wrapf(qres.Response.Error, "Render failed: log:%s", qres.Response.Log)
}

return string(qres.Response.Data), qres, nil
Expand All @@ -120,7 +120,7 @@ func (c *Client) QEval(pkgPath string, expression string) (string, *ctypes.Resul
return "", nil, errors.Wrap(err, "query qeval")
}
if qres.Response.Error != nil {
return "", nil, errors.Wrap(qres.Response.Error, "QEval failed: log:%s", qres.Response.Log)
return "", nil, errors.Wrapf(qres.Response.Error, "QEval failed: log:%s", qres.Response.Log)
}

return string(qres.Response.Data), qres, nil
Expand Down
4 changes: 2 additions & 2 deletions gno.land/pkg/gnoclient/client_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ func (c *Client) BroadcastTxCommit(signedTx *std.Tx) (*ctypes.ResultBroadcastTxC
}

if bres.CheckTx.IsErr() {
return bres, errors.Wrap(bres.CheckTx.Error, "check transaction failed: log:%s", bres.CheckTx.Log)
return bres, errors.Wrapf(bres.CheckTx.Error, "check transaction failed: log:%s", bres.CheckTx.Log)
}
if bres.DeliverTx.IsErr() {
return bres, errors.Wrap(bres.DeliverTx.Error, "deliver transaction failed: log:%s", bres.DeliverTx.Log)
return bres, errors.Wrapf(bres.DeliverTx.Error, "deliver transaction failed: log:%s", bres.DeliverTx.Log)
}

return bres, nil
Expand Down
14 changes: 7 additions & 7 deletions gno.land/pkg/sdk/vm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) (err error) {
case store.OutOfGasException: // panic in consumeGas()
panic(r)
default:
err = errors.Wrap(fmt.Errorf("%v", r), "VM addpkg panic: %v\n%s\n",
err = errors.Wrapf(fmt.Errorf("%v", r), "VM addpkg panic: %v\n%s\n",
r, m2.String())
return
}
Expand Down Expand Up @@ -491,10 +491,10 @@ func (vm *VMKeeper) Call(ctx sdk.Context, msg MsgCall) (res string, err error) {
case store.OutOfGasException: // panic in consumeGas()
panic(r)
case gno.UnhandledPanicError:
err = errors.Wrap(fmt.Errorf("%v", r.Error()), "VM call panic: %s\nStacktrace: %s\n",
err = errors.Wrapf(fmt.Errorf("%v", r.Error()), "VM call panic: %s\nStacktrace: %s\n",
r.Error(), m.ExceptionsStacktrace())
default:
err = errors.Wrap(fmt.Errorf("%v", r), "VM call panic: %v\nMachine State:%s\nStacktrace: %s\n",
err = errors.Wrapf(fmt.Errorf("%v", r), "VM call panic: %v\nMachine State:%s\nStacktrace: %s\n",
r, m.String(), m.Stacktrace().String())
return
}
Expand Down Expand Up @@ -594,7 +594,7 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) {
case store.OutOfGasException: // panic in consumeGas()
panic(r)
default:
err = errors.Wrap(fmt.Errorf("%v", r), "VM run main addpkg panic: %v\n%s\n",
err = errors.Wrapf(fmt.Errorf("%v", r), "VM run main addpkg panic: %v\n%s\n",
r, m.String())
return
}
Expand All @@ -620,7 +620,7 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) {
case store.OutOfGasException: // panic in consumeGas()
panic(r)
default:
err = errors.Wrap(fmt.Errorf("%v", r), "VM run main call panic: %v\n%s\n",
err = errors.Wrapf(fmt.Errorf("%v", r), "VM run main call panic: %v\n%s\n",
r, m2.String())
return
}
Expand Down Expand Up @@ -750,7 +750,7 @@ func (vm *VMKeeper) QueryEval(ctx sdk.Context, pkgPath string, expr string) (res
case store.OutOfGasException: // panic in consumeGas()
panic(r)
default:
err = errors.Wrap(fmt.Errorf("%v", r), "VM query eval panic: %v\n%s\n",
err = errors.Wrapf(fmt.Errorf("%v", r), "VM query eval panic: %v\n%s\n",
r, m.String())
return
}
Expand Down Expand Up @@ -816,7 +816,7 @@ func (vm *VMKeeper) QueryEvalString(ctx sdk.Context, pkgPath string, expr string
case store.OutOfGasException: // panic in consumeGas()
panic(r)
default:
err = errors.Wrap(fmt.Errorf("%v", r), "VM query eval string panic: %v\n%s\n",
err = errors.Wrapf(fmt.Errorf("%v", r), "VM query eval string panic: %v\n%s\n",
r, m.String())
return
}
Expand Down
26 changes: 13 additions & 13 deletions gnovm/pkg/gnolang/op_expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ func (m *Machine) doOpSelector() {

func (m *Machine) doOpSlice() {
sx := m.PopExpr().(*SliceExpr)
var low, high, max int = -1, -1, -1
var lowVal, highVal, maxVal int = -1, -1, -1
// max
if sx.Max != nil {
max = m.PopValue().ConvertGetInt()
maxVal = m.PopValue().ConvertGetInt()
}
// high
if sx.High != nil {
high = m.PopValue().ConvertGetInt()
highVal = m.PopValue().ConvertGetInt()
}
// low
if sx.Low != nil {
low = m.PopValue().ConvertGetInt()
lowVal = m.PopValue().ConvertGetInt()
} else {
low = 0
lowVal = 0
}
// slice base x
xv := m.PopValue()
Expand All @@ -114,14 +114,14 @@ func (m *Machine) doOpSlice() {
}
// fill default based on xv
if sx.High == nil {
high = xv.GetLength()
highVal = xv.GetLength()
}
// all low:high:max cases
if max == -1 {
sv := xv.GetSlice(m.Alloc, low, high)
if maxVal == -1 {
sv := xv.GetSlice(m.Alloc, lowVal, highVal)
m.PushValue(sv)
} else {
sv := xv.GetSlice2(m.Alloc, low, high, max)
sv := xv.GetSlice2(m.Alloc, lowVal, highVal, maxVal)
m.PushValue(sv)
}
}
Expand Down Expand Up @@ -593,16 +593,16 @@ func (m *Machine) doOpSliceLit2() {
// peek slice type.
st := m.PeekValue(1).V.(TypeValue).Type
// calculate maximum index.
max := 0
maxVal := 0
for i := 0; i < el; i++ {
itv := tvs[i*2+0]
idx := itv.ConvertGetInt()
if idx > max {
max = idx
if idx > maxVal {
maxVal = idx
}
}
// construct element buf slice.
es := make([]TypedValue, max+1)
es := make([]TypedValue, maxVal+1)
for i := 0; i < el; i++ {
itv := tvs[i*2+0]
vtv := tvs[i*2+1]
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ func backendPackageIndexKey(index uint64) string {
}

func backendPackagePathKey(path string) string {
return fmt.Sprintf("pkg:" + path)
return "pkg:" + path
}

// ----------------------------------------
Expand Down
36 changes: 22 additions & 14 deletions gnovm/pkg/gnolang/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@
return string(tid)
}

func typeid(f string, args ...interface{}) (tid TypeID) {
func typeid(s string) (tid TypeID) {
x := TypeID(s)
if debug {
debug.Println("TYPEID", s)
}

Check warning on line 48 in gnovm/pkg/gnolang/types.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/types.go#L47-L48

Added lines #L47 - L48 were not covered by tests
return x
}

func typeidf(f string, args ...interface{}) (tid TypeID) {
fs := fmt.Sprintf(f, args...)
x := TypeID(fs)
if debug {
Expand Down Expand Up @@ -521,7 +529,7 @@

func (at *ArrayType) TypeID() TypeID {
if at.typeid.IsZero() {
at.typeid = typeid("[%d]%s", at.Len, at.Elt.TypeID().String())
at.typeid = typeidf("[%d]%s", at.Len, at.Elt.TypeID().String())
}
return at.typeid
}
Expand Down Expand Up @@ -564,9 +572,9 @@
func (st *SliceType) TypeID() TypeID {
if st.typeid.IsZero() {
if st.Vrd {
st.typeid = typeid("...%s", st.Elt.TypeID().String())
st.typeid = typeidf("...%s", st.Elt.TypeID().String())
} else {
st.typeid = typeid("[]%s", st.Elt.TypeID().String())
st.typeid = typeidf("[]%s", st.Elt.TypeID().String())
}
}
return st.typeid
Expand Down Expand Up @@ -607,7 +615,7 @@

func (pt *PointerType) TypeID() TypeID {
if pt.typeid.IsZero() {
pt.typeid = typeid("*%s", pt.Elt.TypeID().String())
pt.typeid = typeidf("*%s", pt.Elt.TypeID().String())
}
return pt.typeid
}
Expand Down Expand Up @@ -748,7 +756,7 @@
// may have the same TypeID if and only if neither have
// unexported fields. st.PkgPath is only included in field
// names that are not uppercase.
st.typeid = typeid(
st.typeid = typeidf(
"struct{%s}",
FieldTypeList(st.Fields).TypeIDForPackage(st.PkgPath),
)
Expand Down Expand Up @@ -1078,11 +1086,11 @@
if ct.typeid.IsZero() {
switch ct.Dir {
case SEND | RECV:
ct.typeid = typeid("chan{%s}" + ct.Elt.TypeID().String())
ct.typeid = typeidf("chan{%s}", ct.Elt.TypeID().String())
case SEND:
ct.typeid = typeid("<-chan{%s}" + ct.Elt.TypeID().String())
ct.typeid = typeidf("<-chan{%s}", ct.Elt.TypeID().String())

Check warning on line 1091 in gnovm/pkg/gnolang/types.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/types.go#L1091

Added line #L1091 was not covered by tests
case RECV:
ct.typeid = typeid("chan<-{%s}" + ct.Elt.TypeID().String())
ct.typeid = typeidf("chan<-{%s}", ct.Elt.TypeID().String())

Check warning on line 1093 in gnovm/pkg/gnolang/types.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/types.go#L1093

Added line #L1093 was not covered by tests
default:
panic("should not happen")
}
Expand Down Expand Up @@ -1298,7 +1306,7 @@
}
*/
if ft.typeid.IsZero() {
ft.typeid = typeid(
ft.typeid = typeidf(
"func(%s)(%s)",
// pp,
ps.UnnamedTypeID(),
Expand Down Expand Up @@ -1361,7 +1369,7 @@

func (mt *MapType) TypeID() TypeID {
if mt.typeid.IsZero() {
mt.typeid = typeid(
mt.typeid = typeidf(
"map[%s]%s",
mt.Key.TypeID().String(),
mt.Value.TypeID().String(),
Expand Down Expand Up @@ -1489,7 +1497,7 @@
}

func DeclaredTypeID(pkgPath string, name Name) TypeID {
return typeid("%s.%s", pkgPath, name)
return typeidf("%s.%s", pkgPath, name)
}

func (dt *DeclaredType) String() string {
Expand Down Expand Up @@ -1787,9 +1795,9 @@
// > (e.g., base64 instead of "encoding/base64") and is not
// > guaranteed to be unique among types. To test for type identity,
// > compare the Types directly.
nt.typeid = typeid("go:%s.%s", nt.Type.PkgPath(), nt.Type.String())
nt.typeid = typeidf("go:%s.%s", nt.Type.PkgPath(), nt.Type.String())
} else {
nt.typeid = typeid("go:%s.%s", nt.Type.PkgPath(), nt.Type.Name())
nt.typeid = typeidf("go:%s.%s", nt.Type.PkgPath(), nt.Type.Name())
}
}
return nt.typeid
Expand Down
48 changes: 24 additions & 24 deletions gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -2248,41 +2248,41 @@
}
}

func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue {
if low < 0 {
func (tv *TypedValue) GetSlice2(alloc *Allocator, lowVal, highVal, maxVal int) TypedValue {
if lowVal < 0 {
panic(fmt.Sprintf(
"invalid slice index %d (index must be non-negative)",
low))
lowVal))

Check warning on line 2255 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2255

Added line #L2255 was not covered by tests
}
if high < 0 {
if highVal < 0 {
panic(fmt.Sprintf(
"invalid slice index %d (index must be non-negative)",
high))
highVal))

Check warning on line 2260 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2260

Added line #L2260 was not covered by tests
}
if max < 0 {
if maxVal < 0 {
panic(fmt.Sprintf(
"invalid slice index %d (index must be non-negative)",
max))
maxVal))

Check warning on line 2265 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2265

Added line #L2265 was not covered by tests
}
if low > high {
if lowVal > highVal {
panic(fmt.Sprintf(
"invalid slice index %d > %d",
low, high))
lowVal, highVal))

Check warning on line 2270 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2270

Added line #L2270 was not covered by tests
}
if high > max {
if highVal > maxVal {
panic(fmt.Sprintf(
"invalid slice index %d > %d",
high, max))
highVal, maxVal))

Check warning on line 2275 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2275

Added line #L2275 was not covered by tests
}
if tv.GetCapacity() < high {
if tv.GetCapacity() < highVal {
panic(fmt.Sprintf(
"slice bounds out of range [%d:%d:%d] with capacity %d",
low, high, max, tv.GetCapacity()))
lowVal, highVal, maxVal, tv.GetCapacity()))

Check warning on line 2280 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2280

Added line #L2280 was not covered by tests
}
if tv.GetCapacity() < max {
if tv.GetCapacity() < maxVal {
panic(fmt.Sprintf(
"slice bounds out of range [%d:%d:%d] with capacity %d",
low, high, max, tv.GetCapacity()))
lowVal, highVal, maxVal, tv.GetCapacity()))

Check warning on line 2285 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2285

Added line #L2285 was not covered by tests
}
switch bt := baseOf(tv.T).(type) {
case *ArrayType:
Expand All @@ -2294,15 +2294,15 @@
return TypedValue{
T: st,
V: alloc.NewSlice(
av, // base
low, // low
high-low, // length
max-low, // maxcap
av, // base
lowVal, // low
highVal-lowVal, // length
maxVal-lowVal, // maxcap
),
}
case *SliceType:
if tv.V == nil {
if low != 0 || high != 0 || max != 0 {
if lowVal != 0 || highVal != 0 || maxVal != 0 {

Check warning on line 2305 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2305

Added line #L2305 was not covered by tests
panic("nil slice index out of range")
}
return TypedValue{
Expand All @@ -2314,10 +2314,10 @@
return TypedValue{
T: tv.T,
V: alloc.NewSlice(
sv.Base, // base
sv.Offset+low, // offset
high-low, // length
max-low, // maxcap
sv.Base, // base
sv.Offset+lowVal, // offset
highVal-lowVal, // length
maxVal-lowVal, // maxcap
),
}
default:
Expand Down
1 change: 0 additions & 1 deletion misc/devdeps/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
_ "golang.org/x/tools/cmd/goimports"

// required for formatting, linting, pls.
_ "golang.org/x/tools/gopls"
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
_ "mvdan.cc/gofumpt"

// protoc, genproto
Expand Down
Loading
Loading