Sha256: eb2a1c2a3895310b39c48563fed74879ddc142f3b94e5992bae84df4d7c48947

Contents?: true

Size: 1.03 KB

Versions: 11

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for checking documentation.
    module DocumentationComment
      extend NodePattern::Macros
      include Style::AnnotationComment

      def_node_matcher :constant_definition?, '{class module casgn}'

      private

      def documentation_comment?(node)
        preceding_lines = preceding_lines(node)

        return false unless preceding_comment?(node, preceding_lines.last)

        preceding_lines.any? do |comment|
          !annotation?(comment) && !interpreter_directive_comment?(comment)
        end
      end

      def preceding_comment?(n1, n2)
        n1 && n2 && preceed?(n2, n1) &&
          comment_line?(n2.loc.expression.source)
      end

      def preceding_lines(node)
        processed_source.ast_with_comments[node].select do |line|
          line.loc.line < node.loc.line
        end
      end

      def interpreter_directive_comment?(comment)
        comment.text =~ /^#\s*(frozen_string_literal|encoding):/
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/documentation_comment.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/documentation_comment.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/documentation_comment.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/documentation_comment.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/documentation_comment.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/documentation_comment.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/documentation_comment.rb
rubocop-0.46.0 lib/rubocop/cop/mixin/documentation_comment.rb
rubocop-0.45.0 lib/rubocop/cop/mixin/documentation_comment.rb
rubocop-0.44.1 lib/rubocop/cop/mixin/documentation_comment.rb
rubocop-0.44.0 lib/rubocop/cop/mixin/documentation_comment.rb