gci
gci copied to clipboard
"C" package causes `gci` to output invalid suggestion
What version of GCI are you using?
gci version 0.11.0
Reproduce Steps
1. Save following program to `main.go` 2. Run `gci diff main.go`
Note that it only happens when there is some additional (default) package present.
package main
import (
"C"
"fmt"
_ "golang.org/x/example/hello/reverse"
)
func init() {
var x C.int
fmt.Print(x)
}
What did you expect to see?
No diff.
What did you see instead?
--- main.go
+++ main.go
@@ -7,6 +7,12 @@
_ "golang.org/x/example/hello/reverse"
)
+import (
+ "fmt"
+
+ _ "golang.org/x/example/hello/reverse"
+)
+
func init() {
var x C.int
fmt.Print(x)
As noted in the description, following program doesn't produce any diff:
package main
import (
"C"
"fmt"
)
func init() {
var x C.int
fmt.Print(x)
}
Because GCI consider it is a C block as a whole, need some time to think how to fix it.
For now, you should split C import as single.
@daixiang0 when i use the gci with https://golangci-lint.run/usage/linters/#gci, there is a error like:
How do i need to configure it? Thanks a lot
@SimFG I cannot reproduce it:
root:[gci]$ ./dist/gci diff -s standard -s default --custom-order gci-bug/main.go
--- gci-bug/main.go
+++ gci-bug/main.go
@@ -1,7 +1,8 @@
package main
import "C"
+
import (
- "sort"
"fmt"
+ "sort"
)
root:[gci]$ cat gci-bug/main.go
package main
import "C"
import (
"sort"
"fmt"
)
thnaks a lot