Add ability to skip some of the nodes in AST::ScopeVisitor

This commit is contained in:
Sijawusz Pur Rahnama 2022-04-04 01:34:34 +02:00
parent ad5d56b313
commit 3f7ade573a

View file

@ -8,14 +8,17 @@ module Ameba::AST
@scope_queue = [] of Scope
@current_scope : Scope
@skip : Array(Crystal::ASTNode.class)?
def initialize(@rule, @source)
def initialize(@rule, @source, skip = nil)
@skip = skip.try &.map(&.as(Crystal::ASTNode.class))
@current_scope = Scope.new(@source.ast) # top level scope
@source.ast.accept self
@scope_queue.each { |scope| @rule.test @source, scope.node, scope }
end
private def on_scope_enter(node)
return if skip?(node)
@current_scope = Scope.new(node, @current_scope)
end
@ -182,5 +185,9 @@ module Ameba::AST
private def record_macro?(node)
node.name == RECORD_NODE_NAME && node.args.first?.is_a?(Crystal::Path)
end
private def skip?(node)
!!@skip.try(&.includes?(node.class))
end
end
end