module RuboCop::Cop::Style::AnnotationComment

Common functionality related to annotation comments.

Private Instance Methods

annotation?(comment) click to toggle source
# File lib/rubocop/cop/mixin/annotation_comment.rb, line 10
def annotation?(comment)
  _margin, first_word, colon, space, note = split_comment(comment)
  keyword_appearance?(first_word, colon, space) &&
    !just_first_word_of_sentence?(first_word, colon, space, note)
end
just_first_word_of_sentence?(first_word, colon, space, note) click to toggle source
# File lib/rubocop/cop/mixin/annotation_comment.rb, line 26
def just_first_word_of_sentence?(first_word, colon, space, note)
  first_word == first_word.capitalize && !colon && space && note
end
keyword?(word) click to toggle source
# File lib/rubocop/cop/mixin/annotation_comment.rb, line 30
def keyword?(word)
  config.for_cop('Style/CommentAnnotation')['Keywords'].include?(word)
end
keyword_appearance?(first_word, colon, space) click to toggle source
# File lib/rubocop/cop/mixin/annotation_comment.rb, line 22
def keyword_appearance?(first_word, colon, space)
  first_word && keyword?(first_word.upcase) && (colon || space)
end
split_comment(comment) click to toggle source
# File lib/rubocop/cop/mixin/annotation_comment.rb, line 16
def split_comment(comment)
  match = comment.text.match(/^(# ?)([A-Za-z]+)(\s*:)?(\s+)?(\S+)?/)
  return false unless match
  match.captures
end