Module: RuboCop::Cop::IgnoredNode

Included in:
Base
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



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

def ignore_node(node)
  ignored_nodes << node
end

#ignored_node?(node) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/rubocop/cop/ignored_node.rb', line 24

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)


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

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

    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