Sha256: bffd020b07d7f3403a29592fe7452572cfea1953fcd9daa576c89a56f9cce745

Contents?: true

Size: 1.05 KB

Versions: 32

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

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

32 entries across 32 versions & 3 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/annotation_comment.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.58.2 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.58.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.58.0 lib/rubocop/cop/mixin/annotation_comment.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.57.2 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.57.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.57.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.56.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.55.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.54.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.53.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.52.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.52.0 lib/rubocop/cop/mixin/annotation_comment.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/annotation_comment.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/annotation_comment.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/annotation_comment.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/annotation_comment.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/annotation_comment.rb