Class: RuboCop::Cop::Style::CommentAnnotation
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Style::CommentAnnotation
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/style/comment_annotation.rb
Overview
Checks that comment annotation keywords are written according to guidelines.
Annotation keywords can be specified by overriding the cop’s ‘Keywords` configuration. Keywords are allowed to be single words or phrases.
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.
Constant Summary collapse
- MSG_COLON_STYLE =
'Annotation keywords like `%<keyword>s` should be all ' \ 'upper case, followed by a colon, and a space, ' \ 'then a note describing the problem.'
- MSG_SPACE_STYLE =
'Annotation keywords like `%<keyword>s` should be all ' \ 'upper case, followed by a space, ' \ 'then a note describing the problem.'
- MISSING_NOTE =
'Annotation comment, with keyword `%<keyword>s`, is missing a note.'
Instance Method Summary collapse
Methods included from AutoCorrector
Instance Method Details
#on_new_investigation ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rubocop/cop/style/comment_annotation.rb', line 73 def on_new_investigation processed_source.comments.each_with_index do |comment, index| next unless first_comment_line?(processed_source.comments, index) || inline_comment?(comment) annotation = AnnotationComment.new(comment, keywords) next unless annotation.annotation? && !annotation.correct?(colon: requires_colon?) register_offense(annotation) end end |