Skip to content

Commit

Permalink
Fix checks for mixed blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krivak committed Sep 20, 2021
1 parent 411620d commit b60172c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 8 additions & 6 deletions checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
14 changes: 14 additions & 0 deletions testdata/check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -104,6 +117,7 @@ func CgoExportedFunction(a, b int) int {

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

Expand Down

0 comments on commit b60172c

Please sign in to comment.