Class: RuboCop::Cop::Style::CommentAnnotation

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/style/comment_annotation.rb

Constant Summary collapse

YAYOI_MSG =
"ζ*'ヮ')ζ<うっうー!`%<keyword>s`のような注釈は全部大きい文字にして" \
'コロン、スペースのあとにコメントを書きましょうねー!'.freeze
YAYOI_MISSING_NOTE =
"ζ*'ヮ')ζ<うっうー!" \
'`%<keyword>s`があるけども、肝心のコメントがないですよー!'.freeze

Instance Method Summary collapse

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_with_index do |comment, index|
    next unless first_comment_line?(processed_source.comments, index) ||
                inline_comment?(comment)

    margin, first_word, colon, space, note = split_comment(comment)
    next unless annotation?(comment) &&
                !correct_annotation?(first_word, colon, space, note)

    length = concat_length(first_word, colon, space)
    add_offense(
      comment,
      location: annotation_range(comment, margin, length),
      message: format(message(note), keyword: first_word)
    )
  end
end