From 10698a1cd51434161dc35fc9636213784f024a33 Mon Sep 17 00:00:00 2001 From: Loong Dai Date: Tue, 19 Jul 2022 09:09:37 +0800 Subject: [PATCH] fix comment in the end of files Signed-off-by: Loong Dai --- .../internal/testdata/comment-in-the-tail.cfg.yaml | 1 + pkg/gci/internal/testdata/comment-in-the-tail.in.go | 13 +++++++++++++ .../internal/testdata/comment-in-the-tail.out.go | 13 +++++++++++++ pkg/parse/parse.go | 3 +-- 4 files changed, 28 insertions(+), 2 deletions(-) create mode 120000 pkg/gci/internal/testdata/comment-in-the-tail.cfg.yaml create mode 100644 pkg/gci/internal/testdata/comment-in-the-tail.in.go create mode 100644 pkg/gci/internal/testdata/comment-in-the-tail.out.go diff --git a/pkg/gci/internal/testdata/comment-in-the-tail.cfg.yaml b/pkg/gci/internal/testdata/comment-in-the-tail.cfg.yaml new file mode 120000 index 0000000..b0db9e7 --- /dev/null +++ b/pkg/gci/internal/testdata/comment-in-the-tail.cfg.yaml @@ -0,0 +1 @@ +common.cfg.yaml \ No newline at end of file diff --git a/pkg/gci/internal/testdata/comment-in-the-tail.in.go b/pkg/gci/internal/testdata/comment-in-the-tail.in.go new file mode 100644 index 0000000..2114dbd --- /dev/null +++ b/pkg/gci/internal/testdata/comment-in-the-tail.in.go @@ -0,0 +1,13 @@ +package main +import ( + "fmt" + + g "github.com/golang" + + "github.com/daixiang0/gci" +) + + +type test int + +// test diff --git a/pkg/gci/internal/testdata/comment-in-the-tail.out.go b/pkg/gci/internal/testdata/comment-in-the-tail.out.go new file mode 100644 index 0000000..2114dbd --- /dev/null +++ b/pkg/gci/internal/testdata/comment-in-the-tail.out.go @@ -0,0 +1,13 @@ +package main +import ( + "fmt" + + g "github.com/golang" + + "github.com/daixiang0/gci" +) + + +type test int + +// test diff --git a/pkg/parse/parse.go b/pkg/parse/parse.go index 738cdd2..0ab9b4f 100644 --- a/pkg/parse/parse.go +++ b/pkg/parse/parse.go @@ -90,10 +90,9 @@ func ParseFile(src []byte) (ImportList, int, int, int, error) { headEnd, _, _ := getImports(f.Imports[0]) _, tailStart, _ := getImports(f.Imports[len(f.Imports)-1]) - tailEnd := f.Decls[len(f.Decls)-1].End() sort.Sort(data) - return data, headEnd, tailStart, int(tailEnd), nil + return data, headEnd, tailStart, len(src), nil } // isGenerated reports whether the source file is generated code.