@@ -2,18 +2,16 @@ package checkers
22
33import (
44 "go/ast"
5- "strings"
65
76 "github.com/go-lintpack/lintpack"
87 "github.com/go-lintpack/lintpack/astwalk"
9- "github.com/go-toolsmith/astfmt"
108 "github.com/go-toolsmith/typep"
119)
1210
1311func init () {
1412 var info lintpack.CheckerInfo
1513 info .Name = "stringXbytes"
16- info .Tags = []string {"diagnostic " , "experimental" }
14+ info .Tags = []string {"style " , "experimental" }
1715 info .Summary = "Detects redundant conversions between string and []byte"
1816 info .Before = `copy(b, []byte(s))`
1917 info .After = `copy(b, s)`
@@ -36,12 +34,12 @@ func (c *stringXbytes) VisitExpr(expr ast.Expr) {
3634 typep .IsTypeExpr (c .ctx .TypesInfo , byteCast .Fun ) &&
3735 typep .HasStringProp (c .ctx .TypesInfo .TypeOf (byteCast .Args [0 ])) {
3836
39- c .warn (byteCast , strings . TrimSuffix ( strings . TrimPrefix ( astfmt . Sprint ( byteCast ), "[]byte(" ), ")" ) )
37+ c .warn (byteCast , byteCast . Args [ 0 ] )
4038 }
4139 }
4240}
4341
44- func (c * stringXbytes ) warn (cause * ast.CallExpr , suggestion string ) {
42+ func (c * stringXbytes ) warn (cause * ast.CallExpr , suggestion ast. Expr ) {
4543 c .ctx .Warn (cause , "can simplify `%s` to `%s`" ,
4644 cause , suggestion )
4745}
0 commit comments