Module: RuboCop::Cop::IgnoredNode

Included in:
Cop, Style::AlignHash
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)


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

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
23
24
# File 'lib/rubocop/cop/ignored_node.rb', line 11

def part_of_ignored_node?(node)
  ignored_nodes.map(&:loc).any? do |ignored_loc|
    if ignored_loc.expression.begin_pos > node.loc.expression.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.loc.expression.end_pos
  end
end