Class: Rubocop::Cop::Style::CommentAnnotation
- Defined in:
- lib/rubocop/cop/style/comment_annotation.rb
Overview
This cop checks that comment annotation keywords are written according to guidelines.
Constant Summary collapse
- MSG =
'Annotation keywords should be all upper case, followed by a ' \ 'colon and a space, then a note describing the problem.'
Constants inherited from Cop
Instance Attribute Summary
Attributes inherited from Cop
#config, #corrections, #offences, #processed_source
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, all, #autocorrect?, #convention, #cop_config, cop_name, #cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, non_rails, rails?, style?, #support_autocorrect?, #warning
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#investigate(processed_source) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rubocop/cop/style/comment_annotation.rb', line 12 def investigate(processed_source) processed_source.comments.each do |comment| match = comment.text.match(/^(# ?)([A-Za-z]+)(\s*:)?(\s+)?(\S+)?/) if match margin, first_word, colon, space, note = *match.captures if annotation?(first_word, colon, space, note) && !correct_annotation?(first_word, colon, space, note) start = comment.loc.expression.begin_pos + margin.length length = first_word.length + (colon || '').length range = Parser::Source::Range.new(processed_source.buffer, start, start + length) convention(nil, range) end end end end |
#keywords ⇒ Object
30 31 32 |
# File 'lib/rubocop/cop/style/comment_annotation.rb', line 30 def keywords cop_config['Keywords'] end |