Skip to content

Commit 170d65c

Browse files
authored
checkers: followup for go-critic#773 (go-critic#774)
- Use "style" tag instead of "diagnostic" - Use byteCast.Args[0] instead of strings woodoo Signed-off-by: Iskander Sharipov <[email protected]>
1 parent f54bdb6 commit 170d65c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

checkers/stringXbytes_checker.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ package checkers
22

33
import (
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

1311
func 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

Comments
 (0)