Skip to content

Commit f41657b

Browse files
author
Denis Krivak
committed
Fix panic with single parenthesis in comment.
1 parent 30ce07f commit f41657b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

godot.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ func checkLastChar(s string) bool {
291291
}
292292
// Trim parenthesis for cases when the whole sentence is inside parenthesis
293293
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+
}
294299
for _, ch := range lastChars {
295300
if string(s[len(s)-1]) == ch {
296301
return true

godot_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ func TestCheckComment(t *testing.T) {
150150
ok: false,
151151
pos: position{line: 0, column: 17},
152152
},
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+
},
153165
// Multiline comments
154166
{
155167
name: "multiline comment: ok",
@@ -271,6 +283,18 @@ func TestCheckComment(t *testing.T) {
271283
ok: false,
272284
pos: position{line: 2, column: 7},
273285
},
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+
},
274298
}
275299

276300
for _, tt := range testCases {

0 commit comments

Comments
 (0)