lib/packwerk/reference_extractor.rb in packwerk-3.2.1 vs lib/packwerk/reference_extractor.rb in packwerk-3.2.2
- old
+ new
@@ -78,11 +78,16 @@
end
def reference_from_node(node, ancestors:, relative_file:)
constant_name = T.let(nil, T.nilable(String))
@constant_name_inspectors.each do |inspector|
- constant_name = inspector.constant_name_from_node(node, ancestors: ancestors)
+ constant_name = inspect_node(
+ inspector,
+ node: node,
+ ancestors: ancestors,
+ relative_file: relative_file
+ )
break if constant_name
end
if constant_name
@@ -94,9 +99,32 @@
)
end
end
private
+
+ sig do
+ params(
+ inspector: ConstantNameInspector,
+ node: Parser::AST::Node,
+ ancestors: T::Array[Parser::AST::Node],
+ relative_file: String
+ ).returns(T.nilable(String))
+ end
+ def inspect_node(inspector, node:, ancestors:, relative_file:)
+ inspector.constant_name_from_node(node, ancestors: ancestors, relative_file: relative_file)
+ rescue ArgumentError => error
+ if error.message == "unknown keyword: :relative_file"
+ T.unsafe(inspector).constant_name_from_node(node, ancestors: ancestors).tap do
+ warn(<<~MSG.squish)
+ #{T.cast(inspector, Object).class}#reference_from_node without a relative_file: keyword
+ argument is deprecated and will be required in Packwerk 3.1.1.
+ MSG
+ end
+ else
+ raise
+ end
+ end
sig do
params(
constant_name: String,
node: Parser::AST::Node,