Skip to content

Commit a7791d4

Browse files
committed
Remove already_extends? helper method
`already_extends?` looks through child nodes to find pre-existing `extends`. As they are wrapped in a `Prism::StatementsNode` they are not currently being detected However, this logic isn't necessary as we will want to insert an `extend` statement prior to any using it regardless. This commit removes the helper method and its checks
1 parent 21e5071 commit a7791d4

2 files changed

Lines changed: 2 additions & 30 deletions

File tree

lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs/base_translator.rb

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ def apply_class_annotations(node)
234234
# Only translate (and `extend ::T::Helpers`) when there's at least one *known* class
235235
# annotation. A node with only unknown annotations (e.g. `@private`) is left untouched.
236236
if comments.class_annotations.any?
237-
unless already_extends?(node, /^(::)?T::Helpers$/)
238-
extend_with("::T::Helpers", into: node, at: insert_pos)
239-
end
237+
extend_with("::T::Helpers", into: node, at: insert_pos)
240238

241239
comments.annotations.reverse_each do |annotation|
242240
content = case annotation.string
@@ -286,9 +284,7 @@ def apply_class_annotations(node)
286284
next
287285
end
288286

289-
unless already_extends?(node, /^(::)?T::Generic$/)
290-
extend_with("::T::Generic", into: node, at: insert_pos)
291-
end
287+
extend_with("::T::Generic", into: node, at: insert_pos)
292288

293289
type_params.each do |type_param|
294290
type_member = "#{type_param.name} = type_member"
@@ -395,22 +391,6 @@ def rewrite_annotation(annotation, is_known:) = nil # no-op
395391
#: (String mixin_name, into: PrismTypes::anyScopeNode, at: Integer) -> void
396392
def extend_with(mixin_name, into:, at:) = raise
397393

398-
#: (PrismTypes::anyScopeNode, Regexp) -> bool
399-
def already_extends?(node, constant_regex)
400-
node.child_nodes.any? do |c|
401-
next false unless c.is_a?(Prism::CallNode)
402-
next false unless c.message == "extend"
403-
next false unless c.receiver.nil? || c.receiver.is_a?(Prism::SelfNode)
404-
next false unless c.arguments&.arguments&.size == 1
405-
406-
arg = c.arguments&.arguments&.first
407-
next false unless arg.is_a?(Prism::ConstantPathNode)
408-
next false unless arg.slice.match?(constant_regex)
409-
410-
true
411-
end
412-
end
413-
414394
#: (Array[Prism::Comment]) -> Array[Spoom::RBS::TypeAlias]
415395
def collect_type_aliases(comments)
416396
type_aliases = [] #: Array[Spoom::RBS::TypeAlias]

rbi/spoom.rbi

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3369,14 +3369,6 @@ class Spoom::Sorbet::Translate::RBSCommentsToSorbetSigs::BaseTranslator < ::Spoo
33693369

33703370
private
33713371

3372-
sig do
3373-
params(
3374-
node: T.any(::Prism::ClassNode, ::Prism::ModuleNode, ::Prism::SingletonClassNode),
3375-
constant_regex: ::Regexp
3376-
).returns(T::Boolean)
3377-
end
3378-
def already_extends?(node, constant_regex); end
3379-
33803372
sig do
33813373
abstract
33823374
.params(

0 commit comments

Comments
 (0)