Skip to content

dev: avoid string conversion by passing byte slice #5304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/goformatters/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func NewAnalyzer(logger logutils.Log, doc string, formatter Formatter) *analysis
Doc: doc,
Run: func(pass *analysis.Pass) (any, error) {
for _, file := range pass.Files {
position, isGoFiles := goanalysis.GetGoFilePosition(pass, file)
if !isGoFiles {
position, isGoFile := goanalysis.GetGoFilePosition(pass, file)
if !isGoFile {
continue
}

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

theDiff := diff.Diff(oldName, input, newName, output)
patch := diff.Diff(oldName, input, newName, output)

err = internal.ExtractDiagnosticFromPatch(pass, file, string(theDiff), logger)
err = internal.ExtractDiagnosticFromPatch(pass, file, patch, logger)
if err != nil {
return nil, fmt.Errorf("can't extract issues from %s diff output %q: %w", formatter.Name(), string(theDiff), err)
return nil, fmt.Errorf("can't extract issues from %s diff output %q: %w", formatter.Name(), patch, err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/goformatters/internal/commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package internal

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

// FormatterLogger must be use only when the context logger is not available.
// FormatterLogger must be used only when the context logger is not available.
var FormatterLogger = logutils.NewStderrLog(logutils.DebugKeyFormatter)
6 changes: 3 additions & 3 deletions pkg/goformatters/internal/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,16 @@ func parseDiffLines(h *diffpkg.Hunk) []diffLine {
func ExtractDiagnosticFromPatch(
pass *analysis.Pass,
file *ast.File,
patch string,
patch []byte,
logger logutils.Log,
) error {
diffs, err := diffpkg.ParseMultiFileDiff([]byte(patch))
diffs, err := diffpkg.ParseMultiFileDiff(patch)
if err != nil {
return fmt.Errorf("can't parse patch: %w", err)
}

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

ft := pass.Fset.File(file.Pos())
Expand Down
Loading