Sha256: 01bc81d587ab4a05f9684494506c9d39d0095f085b3229f38342dcc610798af0

Contents?: true

Size: 1.13 KB

Versions: 19

Compression:

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

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/annotation_comment.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.33.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.32.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.32.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.31.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.30.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.30.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.29.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.29.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.28.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.27.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.27.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.26.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.26.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.25.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.24.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.24.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.23.0 lib/rubocop/cop/mixin/annotation_comment.rb