Skip to content

Commit 50cd6b7

Browse files
authored
fix ^M (#168)
Signed-off-by: Loong <[email protected]>
1 parent 52e43a4 commit 50cd6b7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pkg/gci/gci.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ func LoadFormatGoFile(file io.FileObj, cfg config.Config) (src, dist []byte, err
201201
for _, s := range slices {
202202
i += copy(dist[i:], s)
203203
}
204+
205+
// remove ^M(\r\n) from Win to Unix
206+
dist = bytes.ReplaceAll(dist, []byte{utils.WinLinebreak}, []byte{utils.Linebreak})
207+
204208
log.L().Debug(fmt.Sprintf("raw:\n%s", dist))
205209
dist, err = goFormat.Source(dist)
206210
if err != nil {

pkg/utils/constants.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package utils
22

33
const (
4-
Indent = '\t'
5-
Linebreak = '\n'
4+
Indent = '\t'
5+
Linebreak = '\n'
6+
WinLinebreak = '\r'
67

78
Colon = ":"
89

0 commit comments

Comments
 (0)