Module: RuboCop::Cop::IgnoredNode

Included in:
Cop
Defined in:
lib/rubocop/cop/ignored_node.rb

Overview

Handles adding and checking ignored nodes.

Instance Method Summary collapse

Instance Method Details

#ignore_node(node) ⇒ Object



8
9
10
# File 'lib/rubocop/cop/ignored_node.rb', line 8

def ignore_node(node)
  ignored_nodes << node
end

#ignored_node?(node) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/rubocop/cop/ignored_node.rb', line 27

def ignored_node?(node)
  # Same object found in array?
  ignored_nodes.any? { |n| n.equal?(node) }
end

#part_of_ignored_node?(node) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rubocop/cop/ignored_node.rb', line 12

def part_of_ignored_node?(node)
  ignored_nodes.map(&:loc).any? do |ignored_loc|
    if ignored_loc.expression.begin_pos > node.source_range.begin_pos
      next false
    end

    ignored_end_pos = if ignored_loc.respond_to?(:heredoc_body)
                        ignored_loc.heredoc_end.end_pos
                      else
                        ignored_loc.expression.end_pos
                      end
    ignored_end_pos >= node.source_range.end_pos
  end
end