Skip to content

Commit 62da5c3

Browse files
committed
fix empty lines mapping
1 parent 3e6d4f2 commit 62da5c3

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

line/empty_lines.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ func BuildArgsToSyntaxArgs(args []string) []string {
5050
// NOTE: only collect lines between ast.File, which is the only possible semantic area.
5151
func CollectEmptyLinesForFile(fset *token.FileSet, f *goast.File) []int {
5252
maxLine := -1
53+
54+
//
5355
lineHavingNonEmptyNode := make(map[int]bool)
5456
goast.Inspect(f, func(n goast.Node) bool {
5557
if n == nil {
@@ -74,8 +76,10 @@ func CollectEmptyLinesForFile(fset *token.FileSet, f *goast.File) []int {
7476
maxLine = endLine
7577
}
7678

77-
_, isCmt := n.(*goast.Comment)
78-
if !isCmt {
79+
// check if comment
80+
switch n.(type) {
81+
case *goast.Comment, *goast.CommentGroup:
82+
default:
7983
lineHavingNonEmptyNode[line] = true
8084
if n.End().IsValid() {
8185
lineHavingNonEmptyNode[endLine] = true

line/empty_lines_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99

1010
// go test -run TestCollectEmptyLines -v ./line
1111
func TestCollectEmptyLines(t *testing.T) {
12-
testCode, err := ioutil.ReadFile("./testdata/line_test.go.txt")
12+
// testCode, err := ioutil.ReadFile("./testdata/line_test.go.txt")
13+
testCode, err := ioutil.ReadFile("./testdata/x_ignore.go.txt")
1314
if err != nil {
1415
t.Fatal(err)
1516
}

0 commit comments

Comments
 (0)