Skip to content

Commit

Permalink
fix comment before import blocks
Browse files Browse the repository at this point in the history
Signed-off-by: Loong <long0dai@foxmail.com>
  • Loading branch information
daixiang0 committed Mar 6, 2023
1 parent 4b78992 commit 46a2428
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/gci/gci.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func LoadFormatGoFile(file io.FileObj, cfg config.Config) (src, dist []byte, err
// order by section list
for _, s := range cfg.Sections {
if len(result[s.String()]) > 0 {
if body != nil && len(body) > 0 {
if len(body) > 0 {
body = append(body, utils.Linebreak)
}
for _, d := range result[s.String()] {
Expand All @@ -161,7 +161,6 @@ func LoadFormatGoFile(file io.FileObj, cfg config.Config) (src, dist []byte, err
tail := make([]byte, len(src)-tailStart)
copy(tail, src[tailStart:])

head = append(head, utils.Linebreak)
// ensure C
if cStart != 0 {
head = append(head, src[cStart:cEnd]...)
Expand Down
1 change: 1 addition & 0 deletions pkg/gci/internal/testdata/comment-before-import.cfg.yaml
9 changes: 9 additions & 0 deletions pkg/gci/internal/testdata/comment-before-import.in.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

// comment
import (
"fmt"
"os"

"github.com/daixiang0/gci"
)
9 changes: 9 additions & 0 deletions pkg/gci/internal/testdata/comment-before-import.out.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

// comment
import (
"fmt"
"os"

"github.com/daixiang0/gci"
)

0 comments on commit 46a2428

Please sign in to comment.