Sha256: 333ea57864b9b2c7322a8f46d1666e35289f4f9a4580e18d3f447d17a3cb0ec9

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

# encoding: utf-8
# 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

14 entries across 14 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/annotation_comment.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.43.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.42.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.41.2 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.41.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.41.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.40.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.39.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.38.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.37.2 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.37.1 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.37.0 lib/rubocop/cop/mixin/annotation_comment.rb
rubocop-0.36.0 lib/rubocop/cop/mixin/annotation_comment.rb