Sha256: 7e50f994cb136d72e0a5806e373977fab0f1ae2b97effda310fec29f4092e658

Contents?: true

Size: 1.56 KB

Versions: 6911

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

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

      private

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

      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) &&
            !rubocop_directive_comment?(comment)
        end
      end

      # The args node1 & node2 may represent a RuboCop::AST::Node
      # or a Parser::Source::Comment. Both respond to #loc.
      def preceding_comment?(node1, node2)
        node1 && node2 && precede?(node2, node1) &&
          comment_line?(node2.loc.expression.source)
      end

      # The args node1 & node2 may represent a RuboCop::AST::Node
      # or a Parser::Source::Comment. Both respond to #loc.
      def precede?(node1, node2)
        node2.loc.line - node1.loc.line == 1
      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

      def rubocop_directive_comment?(comment)
        comment.text =~ CommentConfig::COMMENT_DIRECTIVE_REGEXP
      end
    end
  end
end

Version data entries

6,911 entries across 6,905 versions & 27 rubygems

Version Path
ory-client-0.0.1.alpha81 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha80 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha79 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha78 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha77 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha76 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha75 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha74 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha73 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha72 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha71 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha70 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha69 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha68 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha67 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-0.0.1.alpha66 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-oathkeeper-client-0.38.19.beta1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-oathkeeper-client-0.38.18.beta1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-oathkeeper-client-0.38.17.beta1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
avalara_sdk-2.4.7 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb