Sha256: 0c55e1a4591564f3a1cf75e65dca1c9040b9b049e3703507b35f14d38b8e4a58
Contents?: true
Size: 1.21 KB
Versions: 8
Compression:
Stored size: 1.21 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) && !rubocop_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 def rubocop_directive_comment?(comment) comment.text =~ CommentConfig::COMMENT_DIRECTIVE_REGEXP end end end end
Version data entries
8 entries across 8 versions & 1 rubygems