Skip to content

Commit 6483ecf

Browse files
committed
comment: fix hasIgnoreCheck to more pares lines
1 parent 2fd8de7 commit 6483ecf

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

comment.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,30 @@ func (maps Maps) IgnoreLine(fset *token.FileSet, line int, check string) bool {
123123

124124
// hasIgnoreCheck returns true if the provided CommentGroup starts with a comment
125125
// of the form "//lint:ignore Check1[,Check2,...,CheckN] reason" and one of the
126-
// checks matches the provided check. The *ast.CommentGroup is checked directly
127-
// rather than using "cg.Text()" because, starting in Go 1.15, the "cg.Text()" call
128-
// no longer returns directive-style comments (see https://github.com/golang/go/issues/37974).
126+
// checks matches the provided check.
127+
//
128+
// The *ast.CommentGroup is checked directly rather than using "cg.Text()" because,
129+
// starting in Go 1.15, the "cg.Text()" call no longer returns directive-style
130+
// comments (see https://github.com/golang/go/issues/37974).
129131
func hasIgnoreCheck(cg *ast.CommentGroup, check string) bool {
130-
if !strings.HasPrefix(cg.List[0].Text, "//") {
131-
return false
132-
}
132+
for _, list := range cg.List {
133+
if !strings.HasPrefix(list.Text, "//") {
134+
continue
135+
}
133136

134-
s := strings.TrimSpace(cg.List[0].Text[2:])
135-
txt := strings.Split(s, " ")
136-
if len(txt) < 3 || txt[0] != "lint:ignore" {
137-
return false
138-
}
137+
s := strings.TrimSpace(list.Text[2:]) // list.Text[2:]: trim "//"
138+
txt := strings.Split(s, " ")
139+
if len(txt) < 3 || txt[0] != "lint:ignore" {
140+
continue
141+
}
139142

140-
checks := strings.Split(txt[1], ",")
141-
for i := range checks {
142-
if check == checks[i] {
143-
return true
143+
checks := strings.Split(txt[1], ",") // txt[1]: trim "lint:ignore"
144+
for i := range checks {
145+
if check == checks[i] {
146+
return true
147+
}
144148
}
145149
}
150+
146151
return false
147152
}

0 commit comments

Comments
 (0)