Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gci error format go file with windows line separator #212

Open
yougg opened this issue Jul 20, 2024 · 0 comments
Open

gci error format go file with windows line separator #212

yougg opened this issue Jul 20, 2024 · 0 comments

Comments

@yougg
Copy link

yougg commented Jul 20, 2024

gci -v
#gci version 0.13.4

you can reproduce with following steps

first we have one go file number.go with Windows line separator: CRLF

package main

import (
	"math/rand"
	"fmt"
)

func main() {
	fmt.Println("Number0:", rand.Intn(10))
	fmt.Println("Number1:", rand.Intn(10))
	fmt.Println("Number2:", rand.Intn(10))
}

usually the go source file with Windows line separator CRLF came from git checkout with setting git config --global core.autocrlf true

call cat -Ev to show the line endings

> cat -Ev number.go 
package main^M$
^M$
import (^M$
    "math/rand"^M$
    "fmt"^M$
)^M$
^M$
func main() {^M$
    fmt.Println("Number0:", rand.Intn(10))^M$
    fmt.Println("Number1:", rand.Intn(10))^M$
    fmt.Println("Number2:", rand.Intn(10))^M$
}^M$

try format this go file with gci, it will replaces all of CR to LF after import package lines.

gci diff number.go 
--- number.go
+++ number.go
@@ -1,12 +1,16 @@
-package main
-
-import (
-       "math/rand"
-       "fmt"
-)
-
-func main() {
-       fmt.Println("Number0:", rand.Intn(10))
-       fmt.Println("Number1:", rand.Intn(10))
-       fmt.Println("Number2:", rand.Intn(10))
-}
+package main
+
+import (
+       "fmt"
+       "math/rand"
+)
+
+func main() {
+
+       fmt.Println("Number0:", rand.Intn(10))
+
+       fmt.Println("Number1:", rand.Intn(10))
+
+       fmt.Println("Number2:", rand.Intn(10))
+
+}

except correct format result:

--- number.go
+++ number.go
@@ -1,8 +1,8 @@
 package main

 import (
-       "math/rand"
        "fmt"
+       "math/rand"
 )

 func main() {

maybe this PR #170 can help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant