123456789_123456789_123456789_123456789_123456789_

Module: RuboCop::Cop::DocumentationComment

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Macros
Defined in: lib/rubocop/cop/mixin/documentation_comment.rb

Overview

Common functionality for checking documentation.

Instance Method Summary

Instance Method Details

#annotation_keywords (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/documentation_comment.rb', line 47

def annotation_keywords
  config.for_cop('Style/CommentAnnotation')['Keywords']
end

#documentation_comment?(node) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/documentation_comment.rb', line 11

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

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

  preceding_lines.any? do |comment|
    !AnnotationComment.new(comment, annotation_keywords).annotation? &&
      !interpreter_directive_comment?(comment) &&
      !rubocop_directive_comment?(comment)
  end
end

#interpreter_directive_comment?(comment) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/documentation_comment.rb', line 39

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

#precede?(node1, node2) ⇒ Boolean (private)

The args node1 & node2 may represent a RuboCop::AST::Node or a Parser::Source::Comment. Both respond to #loc.

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/documentation_comment.rb', line 31

def precede?(node1, node2)
  node2.loc.line - node1.loc.line == 1
end

#preceding_comment?(node1, node2) ⇒ Boolean (private)

The args node1 & node2 may represent a RuboCop::AST::Node or a Parser::Source::Comment. Both respond to #loc.

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/documentation_comment.rb', line 25

def preceding_comment?(node1, node2)
  node1 && node2 && precede?(node2, node1) && comment_line?(node2.source)
end

#preceding_lines(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/documentation_comment.rb', line 35

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

#rubocop_directive_comment?(comment) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/documentation_comment.rb', line 43

def rubocop_directive_comment?(comment)
  !!DirectiveComment.new(comment).match_captures
end