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

Diff detected on correctly formatted file #125

Closed
mhofstetter opened this issue Nov 16, 2022 · 0 comments · Fixed by #126
Closed

Diff detected on correctly formatted file #125

mhofstetter opened this issue Nov 16, 2022 · 0 comments · Fixed by #126

Comments

@mhofstetter
Copy link
Contributor

What version of GCI are you using?

v0.8.4

Reproduce Steps

Running gci diff on a properly formatted source code file results in a diff. Same applies for the command write.

It seems as the problem is an unintended modification of the underlying src byte array when modifying head & tail which are slices based on the same array.

-> https://github.com/daixiang0/gci/blob/master/pkg/gci/gci.go#L159-L160

./dist/gci diff <...>/github.com/daixiang0/gci/pkg/gci/internal/testdata/with-comment-and-alias.out.go --section Standard --section Default --section "Prefix(github.com/daixiang0)"    
--- /<...>/github.com/daixiang0/gci/pkg/gci/internal/testdata/with-comment-and-alias.out.go
+++ /<...>/github.com/daixiang0/gci/pkg/gci/internal/testdata/with-comment-and-alias.out.go
@@ -1,8 +1,8 @@
 package main
 
+import (
+	"fmt"
 
-import (	"fmt"
-
 	_ "github.com/golang" // golang
 
 	"github.com/daixiang0/gci"

What did you expect to see?

Properly formatted files should not print any diff.

What did you see instead?

Diff gets printed due to uncorrect view of source file.

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

Successfully merging a pull request may close this issue.

1 participant