refactor: avoid one string to []byte conversion
Some checks failed
Go / build (push) Has been cancelled
golangci-lint / lint (push) Has been cancelled
Go / coverage (push) Has been cancelled

This commit is contained in:
Oleksandr Redko 2024-11-20 15:11:12 +02:00 committed by Gabriel Augendre
parent 98578576b8
commit 632a706303

View file

@ -59,7 +59,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
{ {
Pos: assignStmt.Pos(), Pos: assignStmt.Pos(),
End: assignStmt.End(), End: assignStmt.End(),
NewText: []byte(suggested), NewText: suggested,
}, },
}, },
}) })
@ -215,10 +215,10 @@ func getRootIdent(pass *analysis.Pass, node ast.Node) *ast.Ident {
} }
// render returns the pretty-print of the given node // render returns the pretty-print of the given node
func render(fset *token.FileSet, x interface{}) (string, error) { func render(fset *token.FileSet, x interface{}) ([]byte, error) {
var buf bytes.Buffer var buf bytes.Buffer
if err := printer.Fprint(&buf, fset, x); err != nil { if err := printer.Fprint(&buf, fset, x); err != nil {
return "", fmt.Errorf("printing node: %w", err) return nil, fmt.Errorf("printing node: %w", err)
} }
return buf.String(), nil return buf.Bytes(), nil
} }