diff --git a/checks.go b/checks.go index 3caf12a..9e79d97 100644 --- a/checks.go +++ b/checks.go @@ -58,18 +58,20 @@ func checkCommentForPeriod(c comment) *Issue { return nil } - // Shift position by the length of comment's special symbols: /* or // - isBlock := strings.HasPrefix(c.lines[0], "/*") - if (isBlock && pos.line == 1) || !isBlock { - pos.column += 2 - } + // Shift position to its real value. `c.text` doesn't contain comment's + // special symbols: /* or //, and line indentations inside. It also + // contains */ in the end in case of block comment. + pos.column += strings.Index( + c.lines[pos.line-1], + strings.Split(c.text, "\n")[pos.line-1], + ) iss := Issue{ Pos: token.Position{ Filename: c.start.Filename, Offset: c.start.Offset, Line: pos.line + c.start.Line - 1, - Column: pos.column + c.start.Column - 1, + Column: pos.column, }, Message: noPeriodMessage, } diff --git a/testdata/check/main.go b/testdata/check/main.go index 6c1a4b7..0f5b978 100644 --- a/testdata/check/main.go +++ b/testdata/check/main.go @@ -46,6 +46,19 @@ Multiline comment with a period [PASS]. // Single-line comment with a period [PASS]. +// Mixed block of comments, +/* +period must be here [PERIOD_TOP] +*/ + +/* Mixed block of comments, +*/ +// period must be here [PERIOD_TOP] + +/* +// Comment inside comment [PERIOD_TOP] +*/ + // Block comment [PERIOD_DECL] const ( // Inside comment [PERIOD_DECL] @@ -104,6 +117,7 @@ func CgoExportedFunction(a, b int) int { // Кириллица [PERIOD_DECL] func NonLatin() string { + // Тест: Mixed ASCII and non-ASCII chars. return "привет, мир" }