diff --git a/godot.go b/godot.go index 79eb201..29e94d9 100644 --- a/godot.go +++ b/godot.go @@ -291,6 +291,11 @@ func checkLastChar(s string) bool { } // Trim parenthesis for cases when the whole sentence is inside parenthesis s = strings.TrimRight(s, ")") + // Don't panic when comment looks like this: `// )` + // TODO: Check previous line (which is not available in this function right now) + if len(s) == 0 { + return true + } for _, ch := range lastChars { if string(s[len(s)-1]) == ch { return true diff --git a/godot_test.go b/godot_test.go index a7cd491..1e70a7c 100644 --- a/godot_test.go +++ b/godot_test.go @@ -150,6 +150,18 @@ func TestCheckComment(t *testing.T) { ok: false, pos: position{line: 0, column: 17}, }, + { + name: "singleline comment: single closing parenthesis without period", + comment: "// )", + ok: true, + pos: position{}, + }, + { + name: "singleline comment: empty", + comment: "// ", + ok: true, + pos: position{}, + }, // Multiline comments { name: "multiline comment: ok", @@ -271,6 +283,18 @@ func TestCheckComment(t *testing.T) { ok: false, pos: position{line: 2, column: 7}, }, + { + name: "multiline comment: single closing parenthesis without period", + comment: "/*\n" + " )\n" + "*/", + ok: true, + pos: position{}, + }, + { + name: "multiline comment: empty", + comment: "/**/", + ok: true, + pos: position{}, + }, } for _, tt := range testCases {