File tree 2 files changed +29
-0
lines changed 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -291,6 +291,11 @@ func checkLastChar(s string) bool {
291
291
}
292
292
// Trim parenthesis for cases when the whole sentence is inside parenthesis
293
293
s = strings .TrimRight (s , ")" )
294
+ // Don't panic when comment looks like this: `// )`
295
+ // TODO: Check previous line (which is not available in this function right now)
296
+ if len (s ) == 0 {
297
+ return true
298
+ }
294
299
for _ , ch := range lastChars {
295
300
if string (s [len (s )- 1 ]) == ch {
296
301
return true
Original file line number Diff line number Diff line change @@ -150,6 +150,18 @@ func TestCheckComment(t *testing.T) {
150
150
ok : false ,
151
151
pos : position {line : 0 , column : 17 },
152
152
},
153
+ {
154
+ name : "singleline comment: single closing parenthesis without period" ,
155
+ comment : "// )" ,
156
+ ok : true ,
157
+ pos : position {},
158
+ },
159
+ {
160
+ name : "singleline comment: empty" ,
161
+ comment : "// " ,
162
+ ok : true ,
163
+ pos : position {},
164
+ },
153
165
// Multiline comments
154
166
{
155
167
name : "multiline comment: ok" ,
@@ -271,6 +283,18 @@ func TestCheckComment(t *testing.T) {
271
283
ok : false ,
272
284
pos : position {line : 2 , column : 7 },
273
285
},
286
+ {
287
+ name : "multiline comment: single closing parenthesis without period" ,
288
+ comment : "/*\n " + " )\n " + "*/" ,
289
+ ok : true ,
290
+ pos : position {},
291
+ },
292
+ {
293
+ name : "multiline comment: empty" ,
294
+ comment : "/**/" ,
295
+ ok : true ,
296
+ pos : position {},
297
+ },
274
298
}
275
299
276
300
for _ , tt := range testCases {
You can’t perform that action at this time.
0 commit comments