From 226bbc74e8a0245866462fe9593b5411c3dd4c59 Mon Sep 17 00:00:00 2001 From: Kevin Abel Date: Sat, 9 Jan 2021 15:11:30 -0600 Subject: [PATCH] utils/ast: Loose the check for Formula class node Allows single class files with side-effects that load other classes that inherit `Formula`. --- Library/Homebrew/utils/ast.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/utils/ast.rb b/Library/Homebrew/utils/ast.rb index 5c2bed0446..1343ce10d4 100644 --- a/Library/Homebrew/utils/ast.rb +++ b/Library/Homebrew/utils/ast.rb @@ -138,10 +138,14 @@ module Utils def process_formula(formula_contents) processed_source, root_node = process_source(formula_contents) - class_node = if root_node.class_type? - root_node - elsif root_node.begin_type? - root_node.children.find { |n| n.class_type? && n.parent_class&.const_name == "Formula" } + class_node = root_node if root_node.class_type? + if root_node.begin_type? + nodes = root_node.children.select(&:class_type?) + class_node = if nodes.count > 1 + nodes.find { |n| n.parent_class&.const_name == "Formula" } + else + nodes.first + end end raise "Could not find formula class!" if class_node.nil?