From 15e68424b6d5a7c3b79f314bb6647991a44e2861 Mon Sep 17 00:00:00 2001 From: Sergey Vilgelm Date: Sun, 12 Mar 2023 17:43:34 -0700 Subject: [PATCH] fix an issue with extra space in unified diff (#150) The GetUnifiedDiffString returns all lines with an extra character at beginning of each line: `+`, `-`, ` ` (space). The code properly handled the `+` and `-`, but not handled ` ` (space) character at all. So all changed code got an additional space at the beginning of each line. This change fixes the issue. Issue is not critical, because simple `go fmt` removes that space and this is the reason I didn't catch it earlier. Signed-off-by: Sergey Vilgelm --- pkg/analyzer/diff.go | 4 ++-- pkg/analyzer/diff_test.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/analyzer/diff.go b/pkg/analyzer/diff.go index b283cbf..e820757 100644 --- a/pkg/analyzer/diff.go +++ b/pkg/analyzer/diff.go @@ -71,8 +71,8 @@ func GetSuggestedFix(file *token.File, a, b []byte) (*analysis.SuggestedFix, err buf.WriteRune('\n') case '-': // just skip - default: - buf.WriteString(line) + case ' ': + buf.WriteString(line[1:]) buf.WriteRune('\n') } } diff --git a/pkg/analyzer/diff_test.go b/pkg/analyzer/diff_test.go index 617f1e9..5ed9b19 100644 --- a/pkg/analyzer/diff_test.go +++ b/pkg/analyzer/diff_test.go @@ -61,8 +61,8 @@ import ( { Pos: 133, End: 205, - NewText: []byte(` "github.com/daixiang0/gci/pkg/gci" - "github.com/daixiang0/gci/pkg/io" + NewText: []byte(` "github.com/daixiang0/gci/pkg/gci" + "github.com/daixiang0/gci/pkg/io" `, ), }, @@ -93,16 +93,16 @@ import ( { Pos: 35, End: 59, - NewText: []byte(` "go/token" - "strings" + NewText: []byte(` "go/token" + "strings" `, ), }, { Pos: 134, End: 206, - NewText: []byte(` "github.com/daixiang0/gci/pkg/gci" - "github.com/daixiang0/gci/pkg/io" + NewText: []byte(` "github.com/daixiang0/gci/pkg/gci" + "github.com/daixiang0/gci/pkg/io" `, ), },