Skip to content

Commit

Permalink
fix first comment after import block missing (#124)
Browse files Browse the repository at this point in the history
* fix first comment missing

Signed-off-by: Loong <loong.dai@intel.com>

* bump up

Signed-off-by: Loong <loong.dai@intel.com>
  • Loading branch information
daixiang0 committed Nov 16, 2022
1 parent 93e12d5 commit 1887cca
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/gci/internal/testdata/multiple-imports.in.go
Expand Up @@ -13,5 +13,6 @@ import (
import "math"


// main
func main() {
}
1 change: 1 addition & 0 deletions pkg/gci/internal/testdata/multiple-imports.out.go
Expand Up @@ -9,5 +9,6 @@ import (
"github.com/daixiang0/test"
)

// main
func main() {
}
12 changes: 3 additions & 9 deletions pkg/parse/parse.go
Expand Up @@ -86,15 +86,14 @@ func ParseFile(src []byte, filename string) (ImportList, int, int, error) {
headEnd int
// tailStart means the end + 1 of import block
tailStart int
// lastImportStart means the start of last import block
lastImportStart int
data ImportList
data ImportList
)

for i, d := range f.Decls {
for _, d := range f.Decls {
switch d.(type) {
case *ast.GenDecl:
dd := d.(*ast.GenDecl)

if dd.Tok == token.IMPORT {
// there are two cases, both end with linebreak:
// 1.
Expand All @@ -107,15 +106,10 @@ func ParseFile(src []byte, filename string) (ImportList, int, int, error) {
headEnd = int(d.Pos()) - 1
}
tailStart = int(d.End())
lastImportStart = i
}
}
}

if len(f.Decls) > lastImportStart+1 {
tailStart = int(f.Decls[lastImportStart+1].Pos() - 1)
}

for _, imp := range f.Imports {
if imp.Path.Value == C {
if imp.Comment != nil {
Expand Down

0 comments on commit 1887cca

Please sign in to comment.