Skip to content

Commit dbfdb0e

Browse files
committed
Don't check comments without any letters.
1 parent 83b0600 commit dbfdb0e

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

checks.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,30 @@ func checkComments(comments []comment, settings Settings) []Issue {
5656

5757
// checkPeriod checks that the last sentense of the comment ends
5858
// in a period.
59+
//
60+
//nolint:cyclop
5961
func checkPeriod(c comment) *Issue {
62+
lines := strings.Split(c.text, "\n")
63+
64+
// Check if the comment has any letters. Comments like "---" should not
65+
// be checked at all.
66+
var hasLetters bool
67+
for _, line := range lines {
68+
for _, c := range line {
69+
if unicode.IsLetter(c) {
70+
hasLetters = true
71+
break
72+
}
73+
}
74+
}
75+
if !hasLetters {
76+
return nil
77+
}
78+
6079
// Check last non-empty line
6180
var found bool
6281
var line string
6382
var pos position
64-
lines := strings.Split(c.text, "\n")
6583
for i := len(lines) - 1; i >= 0; i-- {
6684
line = strings.TrimRightFunc(lines[i], unicode.IsSpace)
6785
if line == "" {

checks_test.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -207,32 +207,14 @@ func TestCheckPeriod(t *testing.T) {
207207
},
208208
},
209209
{
210-
name: "single closing parenthesis with period",
210+
name: "separator comment without period",
211211
comment: comment{
212-
lines: []string{"//)."},
213-
text: ").",
212+
lines: []string{"// ---"},
213+
text: "---",
214214
start: start,
215215
},
216216
issue: nil,
217217
},
218-
{
219-
name: "single closing parenthesis without period",
220-
comment: comment{
221-
lines: []string{"//)"},
222-
text: ")",
223-
start: start,
224-
},
225-
issue: &Issue{
226-
Pos: token.Position{
227-
Filename: "filename.go",
228-
Offset: 0,
229-
Line: 1,
230-
Column: 4,
231-
},
232-
Message: "Comment should end in a period",
233-
Replacement: "//).",
234-
},
235-
},
236218
}
237219

238220
for _, tt := range testCases {

0 commit comments

Comments
 (0)