Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ def apply_class_annotations(node)
# Only translate (and `extend ::T::Helpers`) when there's at least one *known* class
# annotation. A node with only unknown annotations (e.g. `@private`) is left untouched.
if comments.class_annotations.any?
unless already_extends?(node, /^(::)?T::Helpers$/)
extend_with("::T::Helpers", into: node, at: insert_pos)
end
extend_with("::T::Helpers", into: node, at: insert_pos)

comments.annotations.reverse_each do |annotation|
content = case annotation.string
Expand Down Expand Up @@ -286,9 +284,7 @@ def apply_class_annotations(node)
next
end

unless already_extends?(node, /^(::)?T::Generic$/)
extend_with("::T::Generic", into: node, at: insert_pos)
end
extend_with("::T::Generic", into: node, at: insert_pos)

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

#: (PrismTypes::anyScopeNode, Regexp) -> bool
def already_extends?(node, constant_regex)
node.child_nodes.any? do |c|
next false unless c.is_a?(Prism::CallNode)
next false unless c.message == "extend"
next false unless c.receiver.nil? || c.receiver.is_a?(Prism::SelfNode)
next false unless c.arguments&.arguments&.size == 1

arg = c.arguments&.arguments&.first
next false unless arg.is_a?(Prism::ConstantPathNode)
next false unless arg.slice.match?(constant_regex)

true
end
end

#: (Array[Prism::Comment]) -> Array[Spoom::RBS::TypeAlias]
def collect_type_aliases(comments)
type_aliases = [] #: Array[Spoom::RBS::TypeAlias]
Expand Down
8 changes: 0 additions & 8 deletions rbi/spoom.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -3369,14 +3369,6 @@ class Spoom::Sorbet::Translate::RBSCommentsToSorbetSigs::BaseTranslator < ::Spoo

private

sig do
params(
node: T.any(::Prism::ClassNode, ::Prism::ModuleNode, ::Prism::SingletonClassNode),
constant_regex: ::Regexp
).returns(T::Boolean)
end
def already_extends?(node, constant_regex); end

sig do
abstract
.params(
Expand Down
Loading