Sha256: af97ed013c11517756f2a83f77613969e4699a4343d117d9bf60aa1fb6678bdd

Contents?: true

Size: 1.05 KB

Versions: 6956

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

6,956 entries across 6,931 versions & 29 rubygems

Version Path
mx-platform-ruby-0.3.2 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/annotation_comment.rb
mx-platform-ruby-0.3.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/annotation_comment.rb
passbase-1.3.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/annotation_comment.rb
mfk_openapi_ruby_client-1.0.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/annotation_comment.rb
passbase-1.2.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/annotation_comment.rb
passbase-1.1.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/annotation_comment.rb
passbase-1.0.3 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/annotation_comment.rb
passbase-1.0.2 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/annotation_comment.rb
passbase-1.0.1 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/annotation_comment.rb
passbase-1.0.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/annotation_comment.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.89.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.89.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.88.0 lib/rubocop/cop/mixin/annotation_comment.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.87.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.87.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.86.0 lib/rubocop/cop/mixin/annotation_comment.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/mixin/annotation_comment.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/mixin/annotation_comment.rb