From db278cb9a54ecbfaa09ee81805a388e22287d0b0 Mon Sep 17 00:00:00 2001 From: Kaan Ozkan Date: Fri, 24 Nov 2023 12:02:25 -0500 Subject: [PATCH] Refactor --- gem/lib/rbi-central/runtime/visitor.rb | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/gem/lib/rbi-central/runtime/visitor.rb b/gem/lib/rbi-central/runtime/visitor.rb index a74562a1..4da482b7 100644 --- a/gem/lib/rbi-central/runtime/visitor.rb +++ b/gem/lib/rbi-central/runtime/visitor.rb @@ -20,20 +20,22 @@ def initialize(context) def visit(node) return unless node - skip = validate_node!(node) - visit_all(node.nodes) if node.is_a?(RBI::Tree) && !skip - end - - sig { params(node: RBI::Node).returns(T.nilable(T.any(T::Boolean, Module))) } - def validate_node!(node) annotations = validate_annotations!(node) - - # Do not test definitions tagged `@shim` - if annotations.include?("shim") - return true if node.is_a?(RBI::Class) || node.is_a?(RBI::Module) - return false + if is_shim?(annotations) + return if node.is_a?(RBI::Class) || node.is_a?(RBI::Module) + else + validate_definition!(node, annotations) end + visit_all(node.nodes) if node.is_a?(RBI::Tree) + end + + def is_shim?(annotations) + annotations.include?("shim") + end + + sig { params(node: RBI::Node, annotations: T::Array[String]).void } + def validate_definition!(node, annotations) loc = T.must(node.loc) case node