Method: RuboCop::Cop::Style::CommentAnnotation#investigate

Defined in:
lib/rubocop/cop/style/comment_annotation.rb

#investigate(processed_source) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubocop/cop/style/comment_annotation.rb', line 17

def investigate(processed_source)
  processed_source.comments.each do |comment|
    margin, first_word, colon, space, note = split_comment(comment)
    next unless annotation?(comment) &&
                !correct_annotation?(first_word, colon, space, note)

    start = comment.loc.expression.begin_pos + margin.length
    length = first_word.length + colon.to_s.length + space.to_s.length
    source_buffer = comment.loc.expression.source_buffer
    range = Parser::Source::Range.new(source_buffer,
                                      start,
                                      start + length)
    if note
      add_offense(comment, range, format(MSG, first_word))
    else
      add_offense(comment, range, format(MISSING_NOTE, first_word))
    end
  end
end