From 632a706303736ba949bf9a549312c643b38a34e8 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Wed, 20 Nov 2024 15:11:12 +0200 Subject: [PATCH] refactor: avoid one string to []byte conversion --- pkg/analyzer/analyzer.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/analyzer/analyzer.go b/pkg/analyzer/analyzer.go index a65efbb..7b88bf5 100644 --- a/pkg/analyzer/analyzer.go +++ b/pkg/analyzer/analyzer.go @@ -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 }