Skip to content

Commit fb1674e

Browse files
alexandearldez
andauthored
dev: avoid string conversion by passing byte slice (#5304)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent e68d278 commit fb1674e

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

pkg/goformatters/analyzer.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ func NewAnalyzer(logger logutils.Log, doc string, formatter Formatter) *analysis
2121
Doc: doc,
2222
Run: func(pass *analysis.Pass) (any, error) {
2323
for _, file := range pass.Files {
24-
position, isGoFiles := goanalysis.GetGoFilePosition(pass, file)
25-
if !isGoFiles {
24+
position, isGoFile := goanalysis.GetGoFilePosition(pass, file)
25+
if !isGoFile {
2626
continue
2727
}
2828

@@ -40,11 +40,11 @@ func NewAnalyzer(logger logutils.Log, doc string, formatter Formatter) *analysis
4040
newName := filepath.ToSlash(position.Filename)
4141
oldName := newName + ".orig"
4242

43-
theDiff := diff.Diff(oldName, input, newName, output)
43+
patch := diff.Diff(oldName, input, newName, output)
4444

45-
err = internal.ExtractDiagnosticFromPatch(pass, file, string(theDiff), logger)
45+
err = internal.ExtractDiagnosticFromPatch(pass, file, patch, logger)
4646
if err != nil {
47-
return nil, fmt.Errorf("can't extract issues from %s diff output %q: %w", formatter.Name(), string(theDiff), err)
47+
return nil, fmt.Errorf("can't extract issues from %s diff output %q: %w", formatter.Name(), patch, err)
4848
}
4949
}
5050
}

pkg/goformatters/internal/commons.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ package internal
22

33
import "github.com/golangci/golangci-lint/pkg/logutils"
44

5-
// FormatterLogger must be use only when the context logger is not available.
5+
// FormatterLogger must be used only when the context logger is not available.
66
var FormatterLogger = logutils.NewStderrLog(logutils.DebugKeyFormatter)

pkg/goformatters/internal/diff.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,16 @@ func parseDiffLines(h *diffpkg.Hunk) []diffLine {
213213
func ExtractDiagnosticFromPatch(
214214
pass *analysis.Pass,
215215
file *ast.File,
216-
patch string,
216+
patch []byte,
217217
logger logutils.Log,
218218
) error {
219-
diffs, err := diffpkg.ParseMultiFileDiff([]byte(patch))
219+
diffs, err := diffpkg.ParseMultiFileDiff(patch)
220220
if err != nil {
221221
return fmt.Errorf("can't parse patch: %w", err)
222222
}
223223

224224
if len(diffs) == 0 {
225-
return fmt.Errorf("got no diffs from patch parser: %v", patch)
225+
return fmt.Errorf("got no diffs from patch parser: %s", patch)
226226
}
227227

228228
ft := pass.Fset.File(file.Pos())

0 commit comments

Comments
 (0)