@@ -2,18 +2,16 @@ package checkers
2
2
3
3
import (
4
4
"go/ast"
5
- "strings"
6
5
7
6
"github.com/go-lintpack/lintpack"
8
7
"github.com/go-lintpack/lintpack/astwalk"
9
- "github.com/go-toolsmith/astfmt"
10
8
"github.com/go-toolsmith/typep"
11
9
)
12
10
13
11
func init () {
14
12
var info lintpack.CheckerInfo
15
13
info .Name = "stringXbytes"
16
- info .Tags = []string {"diagnostic " , "experimental" }
14
+ info .Tags = []string {"style " , "experimental" }
17
15
info .Summary = "Detects redundant conversions between string and []byte"
18
16
info .Before = `copy(b, []byte(s))`
19
17
info .After = `copy(b, s)`
@@ -36,12 +34,12 @@ func (c *stringXbytes) VisitExpr(expr ast.Expr) {
36
34
typep .IsTypeExpr (c .ctx .TypesInfo , byteCast .Fun ) &&
37
35
typep .HasStringProp (c .ctx .TypesInfo .TypeOf (byteCast .Args [0 ])) {
38
36
39
- c .warn (byteCast , strings . TrimSuffix ( strings . TrimPrefix ( astfmt . Sprint ( byteCast ), "[]byte(" ), ")" ) )
37
+ c .warn (byteCast , byteCast . Args [ 0 ] )
40
38
}
41
39
}
42
40
}
43
41
44
- func (c * stringXbytes ) warn (cause * ast.CallExpr , suggestion string ) {
42
+ func (c * stringXbytes ) warn (cause * ast.CallExpr , suggestion ast. Expr ) {
45
43
c .ctx .Warn (cause , "can simplify `%s` to `%s`" ,
46
44
cause , suggestion )
47
45
}
0 commit comments