Sha256: 7e50f994cb136d72e0a5806e373977fab0f1ae2b97effda310fec29f4092e658

Contents?: true

Size: 1.56 KB

Versions: 6804

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,804 entries across 6,798 versions & 26 rubygems

Version Path
cybrid_api_bank_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_id_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_organization_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_bank_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_id_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_organization_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_bank_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_organization_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_id_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-1.16.2 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_bank_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_organization_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_id_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_bank_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_id_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_organization_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-1.16.1 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
ory-client-1.16.0 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb
cybrid_api_bank_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/documentation_comment.rb