Skip to content

Commit

Permalink
[Fix #5713] Explicitly test, and add documentation note, for behaviou…
Browse files Browse the repository at this point in the history
…r of multiline comment blocks (#8798)
  • Loading branch information
dvandersluis committed Sep 26, 2020
1 parent e86115d commit 2a35e98
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/modules/ROOT/pages/cops_style.adoc
Expand Up @@ -1576,6 +1576,12 @@ folders = %x(find . -type d).split
This cop checks that comment annotation keywords are written according
to guidelines.

NOTE: With a multiline comment block (where each line is only a
comment), only the first line will be able to register an offense, even
if an annotation keyword starts another line. This is done to prevent
incorrect registering of keywords (eg. `review`) inside a paragraph as an
annotation.

=== Examples

[source,ruby]
Expand Down
6 changes: 6 additions & 0 deletions lib/rubocop/cop/style/comment_annotation.rb
Expand Up @@ -6,6 +6,12 @@ module Style
# This cop checks that comment annotation keywords are written according
# to guidelines.
#
# NOTE: With a multiline comment block (where each line is only a
# comment), only the first line will be able to register an offense, even
# if an annotation keyword starts another line. This is done to prevent
# incorrect registering of keywords (eg. `review`) inside a paragraph as an
# annotation.
#
# @example
# # bad
# # TODO make better
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/style/comment_annotation_spec.rb
Expand Up @@ -133,4 +133,15 @@ class ToBeDone
RUBY
end
end

context 'multiline comment' do
it 'only registers an offense on the first line' do
expect_offense(<<~RUBY)
# TODO line 1
^^^^^ Annotation keywords like `TODO` should be all upper case, followed by a colon, and a space, then a note describing the problem.
# TODO line 2
# TODO line 3
RUBY
end
end
end

0 comments on commit 2a35e98

Please sign in to comment.