diff --git a/pkg/gci/internal/testdata/multiple-imports.in.go b/pkg/gci/internal/testdata/multiple-imports.in.go index d0143ca..930ab12 100644 --- a/pkg/gci/internal/testdata/multiple-imports.in.go +++ b/pkg/gci/internal/testdata/multiple-imports.in.go @@ -13,5 +13,6 @@ import ( import "math" +// main func main() { } diff --git a/pkg/gci/internal/testdata/multiple-imports.out.go b/pkg/gci/internal/testdata/multiple-imports.out.go index da6a5c9..f136a04 100644 --- a/pkg/gci/internal/testdata/multiple-imports.out.go +++ b/pkg/gci/internal/testdata/multiple-imports.out.go @@ -9,5 +9,6 @@ import ( "github.com/daixiang0/test" ) +// main func main() { } diff --git a/pkg/parse/parse.go b/pkg/parse/parse.go index 7540d07..ffb9580 100644 --- a/pkg/parse/parse.go +++ b/pkg/parse/parse.go @@ -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. @@ -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 {