Module: Hashira::Smells::Scope

Defined in:
lib/hashira/smells/scope.rb

Constant Summary collapse

TYPES =
[Prism::ClassNode, Prism::ModuleNode, Prism::SingletonClassNode].freeze
FENCES =
(TYPES + [Prism::DefNode]).freeze

Class Method Summary collapse

Class Method Details

.below(root, fences) ⇒ Object



16
17
18
19
20
# File 'lib/hashira/smells/scope.rb', line 16

def below(root, fences)
  found = []
  visit(root, fences) { found << it }
  found
end

.inside(node) ⇒ Object



12
# File 'lib/hashira/smells/scope.rb', line 12

def inside(node) = below(node, FENCES)

.sweep(node) ⇒ Object



14
# File 'lib/hashira/smells/scope.rb', line 14

def sweep(node) = below(node, TYPES)

.visit(root, fences) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/hashira/smells/scope.rb', line 22

def visit(root, fences, &)
  root.compact_child_nodes.each do |child|
    next if fences.include?(child.class)
    yield(child)
    visit(child, fences, &)
  end
end