Sha256: 4ac8d7e89ec94502f8029de7e92701c8e3f8303df4799bb0135c0a38e68f7333

Contents?: true

Size: 1.16 KB

Versions: 50

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

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

        # @api public
        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

        # @api public
        def split_comment(comment)
          match = comment.text.match(/^(# ?)([A-Za-z]+)(\s*:)?(\s+)?(\S+)?/)
          return false unless match

          match.captures
        end

        # @api public
        def keyword_appearance?(first_word, colon, space)
          first_word && keyword?(first_word.upcase) && (colon || space)
        end

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

        # @api public
        def keyword?(word)
          config.for_cop('Style/CommentAnnotation')['Keywords'].include?(word)
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 5 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/mixin/annotation_comment.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/mixin/annotation_comment.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/mixin/annotation_comment.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/mixin/annotation_comment.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/mixin/annotation_comment.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.19.1 lib/rubocop/cop/mixin/annotation_comment.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rubocop-1.18.3/lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.19.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.18.4 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.18.3 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.18.2 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.18.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.18.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.17.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.16.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.16.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.15.0 lib/rubocop/cop/mixin/annotation_comment.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/rubocop-1.14.0/lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-1.14.0 lib/rubocop/cop/mixin/annotation_comment.rb