Skip to content

Commit

Permalink
Fix detecting issues in indented code inside comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krivak committed May 2, 2020
1 parent 4432b5a commit 737cbe5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion godot.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func checkComment(comment string) (line int, ok bool) {
func checkLastChar(s string) bool {
// Don't check comments starting with space indentation - they may
// contain code examples, which shouldn't end with period
if strings.HasPrefix(s, " ") || strings.HasPrefix(s, "\t") {
if strings.HasPrefix(s, " ") || strings.HasPrefix(s, " \t") || strings.HasPrefix(s, "\t") {
return true
}
s = strings.TrimSpace(s)
Expand Down
6 changes: 6 additions & 0 deletions godot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ func TestCheckComment(t *testing.T) {
ok: true,
line: 0,
},
{
name: "singleline comment: code example without period and mixed indentation",
comment: "// \tx == y",
ok: true,
line: 0,
},
{
name: "singleline comment: empty line",
comment: "//",
Expand Down
9 changes: 8 additions & 1 deletion testdata/example_checkall.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ObjectX struct {
}

// Declaration comment without a period, with an indented code example:
// co := ComplexObject{}
// co := ComplexObjectX{}
// fmt.Println(co) // PASS
type ComplexObjectX struct {
// Exported field comment - always PASS
Expand All @@ -51,6 +51,13 @@ type ComplexObjectX struct {
secret int
}

// Declaration comment without a period, with a mixed indented code example:
// co := MessageX{}
// fmt.Println(co) // PASS
type MessageX struct {
Type string
}

// Declaration multiline comment
// second line
// third line with a period PASS.
Expand Down
7 changes: 7 additions & 0 deletions testdata/example_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ type ComplexObject struct {
secret int
}

// Declaration comment without a period, with a mixed indented code example:
// co := Message{}
// fmt.Println(co) // PASS
type Message struct {
Type string
}

// Declaration multiline comment
// second line
// third line with a period PASS.
Expand Down

0 comments on commit 737cbe5

Please sign in to comment.