refactor: avoid one string to []byte conversion
Some checks are pending
Go / build (push) Waiting to run
Go / coverage (push) Blocked by required conditions
golangci-lint / lint (push) Waiting to run

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(),
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
func render(fset *token.FileSet, x interface{}) (string, error) {
func render(fset *token.FileSet, x interface{}) ([]byte, error) {
var buf bytes.Buffer
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
}