@@ -115,7 +115,6 @@ func (p *Nolint) shouldPassIssue(i *result.Issue) (bool, error) {
115
115
if i .FromLinter == linter {
116
116
return false , nil
117
117
}
118
- // TODO: check linter name
119
118
}
120
119
}
121
120
@@ -127,20 +126,30 @@ func extractFileComments(fset *token.FileSet, comments ...*ast.CommentGroup) fil
127
126
for _ , g := range comments {
128
127
for _ , c := range g .List {
129
128
text := strings .TrimLeft (c .Text , "/ " )
130
- if strings .HasPrefix (text , "nolint" ) {
131
- var linters []string
132
- if strings .HasPrefix (text , "nolint:" ) {
133
- text = strings .Split (text , " " )[0 ] // allow arbitrary text after this comment
134
- for _ , linter := range strings .Split (strings .TrimPrefix (text , "nolint:" ), "," ) {
135
- linters = append (linters , strings .TrimSpace (linter ))
136
- }
137
- }
138
- pos := fset .Position (g .Pos ())
129
+ if ! strings .HasPrefix (text , "nolint" ) {
130
+ continue
131
+ }
132
+
133
+ pos := fset .Position (g .Pos ())
134
+ if ! strings .HasPrefix (text , "nolint:" ) { // ignore all linters
139
135
ret = append (ret , comment {
140
- linters : linters ,
141
- line : pos .Line ,
136
+ line : pos .Line ,
142
137
})
138
+ continue
139
+ }
140
+
141
+ // ignore specific linters
142
+ var linters []string
143
+ text = strings .Split (text , "//" )[0 ] // allow another comment after this comment
144
+ linterItems := strings .Split (strings .TrimPrefix (text , "nolint:" ), "," )
145
+ for _ , linter := range linterItems {
146
+ linterName := strings .TrimSpace (linter ) // TODO: validate it here
147
+ linters = append (linters , linterName )
143
148
}
149
+ ret = append (ret , comment {
150
+ linters : linters ,
151
+ line : pos .Line ,
152
+ })
144
153
}
145
154
}
146
155
0 commit comments