Skip to content

Commit

Permalink
fix: bump golangci lint to 1.62 (gnolang#3278)
Browse files Browse the repository at this point in the history
fix gnolang#3066

Bump `golangci-lint` to `1.62`, this bump include the following change.
- Removing `gopls` from direct dependency as it creates some conflict
with the latest version of `golangci-lint`. `gopls` is not meant to be
tracked as a direct dependency tool; it's a personal tool and it's
dependent on the user's Go version, not the project-specific version.
- Update all `printf`-like methods that should not use non-constant
format input. Instead, I choose to duplicate those methods into two
separate methods: one should be dedicated to formatting, and the other
one to simple direct messaging. ex. `errors.Wrap` -> `errors.Wrapf`
- ~Ignoring `gosec` issue with `ripemd160` for now, I will open an issue
to double-check this one.~ ✅ Double-checked with @zivkovicmilos &
@jaekwon, we can ignore it.
- Ignoring `gosec` G115 Integer overflow conversion; there is no
solution to check the overflow in the time of conversion, so I think the
linter shouldn't check for the overflow.


<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
</details>

---------

Signed-off-by: gfanton <[email protected]>
Co-authored-by: Morgan <[email protected]>
  • Loading branch information
2 people authored and Villaquiranm committed Dec 9, 2024
1 parent 069c01b commit a7f1b81
Show file tree
Hide file tree
Showing 35 changed files with 369 additions and 367 deletions.
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 @@ func (tid TypeID) String() string {
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)
}
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) Kind() Kind {

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) Kind() Kind {
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) Kind() Kind {

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 @@ func (st *StructType) TypeID() TypeID {
// 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 @@ func (ct *ChanType) TypeID() TypeID {
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())
case RECV:
ct.typeid = typeid("chan<-{%s}" + ct.Elt.TypeID().String())
ct.typeid = typeidf("chan<-{%s}", ct.Elt.TypeID().String())
default:
panic("should not happen")
}
Expand Down Expand Up @@ -1298,7 +1306,7 @@ func (ft *FuncType) TypeID() TypeID {
}
*/
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) Kind() Kind {

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 (dt *DeclaredType) TypeID() TypeID {
}

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 @@ func (nt *NativeType) TypeID() TypeID {
// > (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) GetSlice(alloc *Allocator, low, high int) TypedValue {
}
}

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))
}
if high < 0 {
if highVal < 0 {
panic(fmt.Sprintf(
"invalid slice index %d (index must be non-negative)",
high))
highVal))
}
if max < 0 {
if maxVal < 0 {
panic(fmt.Sprintf(
"invalid slice index %d (index must be non-negative)",
max))
maxVal))
}
if low > high {
if lowVal > highVal {
panic(fmt.Sprintf(
"invalid slice index %d > %d",
low, high))
lowVal, highVal))
}
if high > max {
if highVal > maxVal {
panic(fmt.Sprintf(
"invalid slice index %d > %d",
high, max))
highVal, maxVal))
}
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()))
}
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()))
}
switch bt := baseOf(tv.T).(type) {
case *ArrayType:
Expand All @@ -2294,15 +2294,15 @@ func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue
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 {
panic("nil slice index out of range")
}
return TypedValue{
Expand All @@ -2314,10 +2314,10 @@ func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue
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"
_ "mvdan.cc/gofumpt"

// protoc, genproto
Expand Down
Loading

0 comments on commit a7f1b81

Please sign in to comment.