Skip to content

Commit 15e6842

Browse files
authored
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 <[email protected]>
1 parent dd1f796 commit 15e6842

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pkg/analyzer/diff.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func GetSuggestedFix(file *token.File, a, b []byte) (*analysis.SuggestedFix, err
7171
buf.WriteRune('\n')
7272
case '-':
7373
// just skip
74-
default:
75-
buf.WriteString(line)
74+
case ' ':
75+
buf.WriteString(line[1:])
7676
buf.WriteRune('\n')
7777
}
7878
}

pkg/analyzer/diff_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ import (
6161
{
6262
Pos: 133,
6363
End: 205,
64-
NewText: []byte(` "github.com/daixiang0/gci/pkg/gci"
65-
"github.com/daixiang0/gci/pkg/io"
64+
NewText: []byte(` "github.com/daixiang0/gci/pkg/gci"
65+
"github.com/daixiang0/gci/pkg/io"
6666
`,
6767
),
6868
},
@@ -93,16 +93,16 @@ import (
9393
{
9494
Pos: 35,
9595
End: 59,
96-
NewText: []byte(` "go/token"
97-
"strings"
96+
NewText: []byte(` "go/token"
97+
"strings"
9898
`,
9999
),
100100
},
101101
{
102102
Pos: 134,
103103
End: 206,
104-
NewText: []byte(` "github.com/daixiang0/gci/pkg/gci"
105-
"github.com/daixiang0/gci/pkg/io"
104+
NewText: []byte(` "github.com/daixiang0/gci/pkg/gci"
105+
"github.com/daixiang0/gci/pkg/io"
106106
`,
107107
),
108108
},

0 commit comments

Comments
 (0)