class RuboCop::Cop::Style::CommentAnnotation

# OPTIMIZE: does not work
# good
# Optimize does not work
# bad
# FIXME: does not work
# good
# fixme: does not work
# bad
# TODO: make better
# good
# TODO:make better
# bad
# TODO: make better
# good
# TODO make better
# bad
@example
to guidelines.
This cop checks that comment annotation keywords are written according

def annotation_range(comment, margin, first_word, colon, space)

def annotation_range(comment, margin, first_word, colon, space)
  start = comment.loc.expression.begin_pos + margin.length
  length = concat_length(first_word, colon, space)
  range_between(start, start + length)
end

def autocorrect(comment)

def autocorrect(comment)
  margin, first_word, colon, space, note = split_comment(comment)
  return if note.nil?
  range = annotation_range(comment, margin, first_word, colon, space)
  ->(corrector) { corrector.replace(range, "#{first_word.upcase}: ") }
end

def concat_length(*args)

def concat_length(*args)
  args.reduce(0) { |acc, elem| acc + elem.to_s.length }
end

def correct_annotation?(first_word, colon, space, note)

def correct_annotation?(first_word, colon, space, note)
  keyword?(first_word) && (colon && space && note || !colon && !note)
end

def first_comment_line?(comments, index)

def first_comment_line?(comments, index)
  index.zero? ||
    comments[index - 1].loc.line < comments[index].loc.line - 1
end

def inline_comment?(comment)

def inline_comment?(comment)
  !comment_line?(comment.loc.expression.source_line)
end

def investigate(processed_source)

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)
    add_offense(
      comment,
      location: annotation_range(comment, margin,
                                 first_word, colon, space),
      message: format(note ? MSG : MISSING_NOTE, keyword: first_word)
    )
  end
end