Skip to content

Commit

Permalink
fix an issue with extra space in unified diff (#150)
Browse files Browse the repository at this point in the history
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 <sergey@vilgelm.com>
  • Loading branch information
SVilgelm authored Mar 13, 2023
1 parent dd1f796 commit 15e6842
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/analyzer/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/analyzer/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
`,
),
},
Expand Down Expand Up @@ -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"
`,
),
},
Expand Down

0 comments on commit 15e6842

Please sign in to comment.