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

"C" package causes gci to output invalid suggestion #166

Open
VirrageS opened this issue Aug 29, 2023 · 5 comments
Open

"C" package causes gci to output invalid suggestion #166

VirrageS opened this issue Aug 29, 2023 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@VirrageS
Copy link

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)
@VirrageS
Copy link
Author

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)
}

@daixiang0 daixiang0 added bug Something isn't working good first issue Good for newcomers labels Sep 18, 2023
@daixiang0
Copy link
Owner

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.

@SimFG
Copy link

SimFG commented Sep 20, 2023

@daixiang0 when i use the gci with https://golangci-lint.run/usage/linters/#gci, there is a error like:
image
image
How do i need to configure it? Thanks a lot

@daixiang0
Copy link
Owner

@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"
)

@SimFG
Copy link

SimFG commented Sep 21, 2023

thnaks a lot

@daixiang0 daixiang0 reopened this Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants