Skip to content

Commit

Permalink
fix: TODO comments after multi-line comments.
Browse files Browse the repository at this point in the history
Fixes an issue where the `TODOScanner.Scan` would return `false` if it
encounters a multi-line comment with no TODOs present in it.

Fixes #1520

Signed-off-by: Ian Lewis <ianmlewis@gmail.com>
  • Loading branch information
ianlewis committed Jul 18, 2024
1 parent 87ad61b commit e98b795
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed

- Fixed a bug where TODOs were not being reported if they were located after a
multi-line comment with no TODOs in the same file
([#1520](https://github.com/ianlewis/todos/issues/1520))

## [0.9.0-rc.2] - 2024-07-17

### Added in 0.9.0-rc.2
Expand Down
16 changes: 9 additions & 7 deletions internal/todos/todos.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ func (t *TODOScanner) Scan() bool {
if next.Multiline {
matches := t.findMultilineMatches(next)
t.next = append(t.next, matches...)
return len(t.next) > 0
}

match := t.findLineMatch(next)
if match != nil {
t.next = append(t.next, match)
return true
if len(t.next) > 0 {
return true
}
} else {
match := t.findLineMatch(next)
if match != nil {
t.next = append(t.next, match)
return true
}
}
}
return false
Expand Down
31 changes: 31 additions & 0 deletions internal/todos/todos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,37 @@ func TestTODOScanner(t *testing.T) {
},
},
},
// Regression test for issue #1520
// Ensure that the TODOScanner continues scanning after finding a
// multi-line comment with no TODOs in it.
"regression_1520.go": {
s: &testScanner{
comments: []*scanner.Comment{
{
Text: "/**\n no match here\n */",
Line: 1,
Multiline: true,
},
{
Text: "// TODO: match",
Line: 5,
},
},
},
config: &Config{
Types: []string{"TODO"},
},
expected: []*TODO{
{
Type: "TODO",
Text: "// TODO: match",
Label: "",
Message: "match",
Line: 5,
CommentLine: 5,
},
},
},
}

for name, tc := range testCases {
Expand Down

0 comments on commit e98b795

Please # to comment.