Skip to content

Commit

Permalink
fix ^M (#168)
Browse files Browse the repository at this point in the history
Signed-off-by: Loong <long0dai@foxmail.com>
  • Loading branch information
daixiang0 authored Sep 6, 2023
1 parent 52e43a4 commit 50cd6b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/gci/gci.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func LoadFormatGoFile(file io.FileObj, cfg config.Config) (src, dist []byte, err
for _, s := range slices {
i += copy(dist[i:], s)
}

// remove ^M(\r\n) from Win to Unix
dist = bytes.ReplaceAll(dist, []byte{utils.WinLinebreak}, []byte{utils.Linebreak})

log.L().Debug(fmt.Sprintf("raw:\n%s", dist))
dist, err = goFormat.Source(dist)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/utils/constants.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package utils

const (
Indent = '\t'
Linebreak = '\n'
Indent = '\t'
Linebreak = '\n'
WinLinebreak = '\r'

Colon = ":"

Expand Down

0 comments on commit 50cd6b7

Please sign in to comment.