Skip to content

Commit 1887cca

Browse files
authored
fix first comment after import block missing (#124)
* fix first comment missing Signed-off-by: Loong <[email protected]> * bump up Signed-off-by: Loong <[email protected]>
1 parent 93e12d5 commit 1887cca

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

pkg/gci/internal/testdata/multiple-imports.in.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ import (
1313
import "math"
1414

1515

16+
// main
1617
func main() {
1718
}

pkg/gci/internal/testdata/multiple-imports.out.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ import (
99
"github.com/daixiang0/test"
1010
)
1111

12+
// main
1213
func main() {
1314
}

pkg/parse/parse.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,14 @@ func ParseFile(src []byte, filename string) (ImportList, int, int, error) {
8686
headEnd int
8787
// tailStart means the end + 1 of import block
8888
tailStart int
89-
// lastImportStart means the start of last import block
90-
lastImportStart int
91-
data ImportList
89+
data ImportList
9290
)
9391

94-
for i, d := range f.Decls {
92+
for _, d := range f.Decls {
9593
switch d.(type) {
9694
case *ast.GenDecl:
9795
dd := d.(*ast.GenDecl)
96+
9897
if dd.Tok == token.IMPORT {
9998
// there are two cases, both end with linebreak:
10099
// 1.
@@ -107,15 +106,10 @@ func ParseFile(src []byte, filename string) (ImportList, int, int, error) {
107106
headEnd = int(d.Pos()) - 1
108107
}
109108
tailStart = int(d.End())
110-
lastImportStart = i
111109
}
112110
}
113111
}
114112

115-
if len(f.Decls) > lastImportStart+1 {
116-
tailStart = int(f.Decls[lastImportStart+1].Pos() - 1)
117-
}
118-
119113
for _, imp := range f.Imports {
120114
if imp.Path.Value == C {
121115
if imp.Comment != nil {

0 commit comments

Comments
 (0)