Sha256: ec59cc340a223b6f52c197a4335397bae24c721c5e924fef76c4795942ea8f40

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # Common functionality related to annotation comments.
      module AnnotationComment
        private

        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

        def split_comment(comment)
          match = comment.text.match(/^(# ?)([A-Za-z]+)(\s*:)?(\s+)?(\S+)?/)
          return false unless match
          margin, first_word, colon, space, note = *match.captures
          [margin, first_word, colon, space, note]
        end

        def keyword_appearance?(first_word, colon, space)
          first_word && keyword?(first_word.upcase) && (colon || space)
        end

        def just_first_word_of_sentence?(first_word, colon, space, note)
          first_word == first_word.capitalize && !colon && space && note
        end

        def keyword?(word)
          config.for_cop('CommentAnnotation')['Keywords'].include?(word)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-0.22.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.21.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.20.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.20.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.19.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.19.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.18.1 lib/rubocop/cop/mixin/annotation_comment.rb