Sha256: 84124d4e9cb679a1b5c8a87d8151e6a6e730df1543195b29e900ab471da9b40c

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 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
          match.captures
        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('Style/CommentAnnotation')['Keywords'].include?(word)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.35.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.34.2 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.34.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.34.0 lib/rubocop/cop/mixin/annotation_comment.rb