Skip to content

Commit b60172c

Browse files
author
Denis Krivak
committed
Fix checks for mixed blocks.
1 parent 411620d commit b60172c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

checks.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,20 @@ func checkCommentForPeriod(c comment) *Issue {
5858
return nil
5959
}
6060

61-
// Shift position by the length of comment's special symbols: /* or //
62-
isBlock := strings.HasPrefix(c.lines[0], "/*")
63-
if (isBlock && pos.line == 1) || !isBlock {
64-
pos.column += 2
65-
}
61+
// Shift position to its real value. `c.text` doesn't contain comment's
62+
// special symbols: /* or //, and line indentations inside. It also
63+
// contains */ in the end in case of block comment.
64+
pos.column += strings.Index(
65+
c.lines[pos.line-1],
66+
strings.Split(c.text, "\n")[pos.line-1],
67+
)
6668

6769
iss := Issue{
6870
Pos: token.Position{
6971
Filename: c.start.Filename,
7072
Offset: c.start.Offset,
7173
Line: pos.line + c.start.Line - 1,
72-
Column: pos.column + c.start.Column - 1,
74+
Column: pos.column,
7375
},
7476
Message: noPeriodMessage,
7577
}

testdata/check/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ Multiline comment with a period [PASS].
4646

4747
// Single-line comment with a period [PASS].
4848

49+
// Mixed block of comments,
50+
/*
51+
period must be here [PERIOD_TOP]
52+
*/
53+
54+
/* Mixed block of comments,
55+
*/
56+
// period must be here [PERIOD_TOP]
57+
58+
/*
59+
// Comment inside comment [PERIOD_TOP]
60+
*/
61+
4962
// Block comment [PERIOD_DECL]
5063
const (
5164
// Inside comment [PERIOD_DECL]
@@ -104,6 +117,7 @@ func CgoExportedFunction(a, b int) int {
104117

105118
// Кириллица [PERIOD_DECL]
106119
func NonLatin() string {
120+
// Тест: Mixed ASCII and non-ASCII chars.
107121
return "привет, мир"
108122
}
109123

0 commit comments

Comments
 (0)