Module: RuboCop::Cop::CommentsHelp

Overview

Help methods for working with nodes containing comments.

Instance Method Summary collapse

Instance Method Details

#comments_contain_disables?(node, cop_name) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubocop/cop/mixin/comments_help.rb', line 25

def comments_contain_disables?(node, cop_name)
  disabled_ranges = processed_source.disabled_line_ranges[cop_name]

  return false unless disabled_ranges

  node_range = node.source_range.line...find_end_line(node)

  disabled_ranges.any? do |disable_range|
    disable_range.cover?(node_range) || node_range.cover?(disable_range)
  end
end

#comments_in_range(node) ⇒ Object



18
19
20
21
22
23
# File 'lib/rubocop/cop/mixin/comments_help.rb', line 18

def comments_in_range(node)
  start_line = node.source_range.line
  end_line = find_end_line(node)

  processed_source.each_comment_in_lines(start_line...end_line)
end

#contains_comments?(node) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rubocop/cop/mixin/comments_help.rb', line 14

def contains_comments?(node)
  comments_in_range(node).any?
end

#source_range_with_comment(node) ⇒ Object



7
8
9
10
11
12
# File 'lib/rubocop/cop/mixin/comments_help.rb', line 7

def source_range_with_comment(node)
  begin_pos = begin_pos_with_comment(node)
  end_pos = end_position_for(node)

  Parser::Source::Range.new(buffer, begin_pos, end_pos)
end