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
2 changes: 2 additions & 0 deletions lib/spoom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ class Error < StandardError; end
require "spoom/sorbet"
require "spoom/cli"
require "spoom/version"

require "spoom/ext/prism_types"
14 changes: 14 additions & 0 deletions lib/spoom/ext/prism_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# typed: strict
# frozen_string_literal: true

module Spoom
module PrismTypes
# Ideally this would just be in a shim in `sorbet/rbi/shims/prism.rbi`, but that causes
# `bundle exec tapioca gem spoom` to fail. It Spoom's translator to rewrite the RBS signature comments into Sigs,
# which try to access the `Prism::AnyScopeNode` constant.
# Because shims aren't executed, no such constant exists at runtime, and the Sig raises a NameError.
#
# So instead, we define it here, where the translator can reify it into a real Sorbet `T.type_alias` at runtime.
#: type anyScopeNode = ::Prism::ClassNode | ::Prism::ModuleNode | ::Prism::SingletonClassNode
end
end
4 changes: 2 additions & 2 deletions lib/spoom/sorbet/metrics/code_metrics_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def visit_call_node(node)

private

#: (Prism::ClassNode | Prism::ModuleNode | Prism::SingletonClassNode) { -> void } -> void
#: (PrismTypes::anyScopeNode) { -> void } -> void
def visit_scope(node, &block)
key = node_key(node)
@counters.increment(key)
Expand Down Expand Up @@ -216,7 +216,7 @@ def collect_last_srb_sigs
sigs
end

#: (Prism::ClassNode | Prism::ModuleNode | Prism::SingletonClassNode) -> String
#: (PrismTypes::anyScopeNode) -> String
def node_key(node)
case node
when Prism::ClassNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def apply_overloads_strategy(signatures, method_name:, location:)
end
end

#: (Prism::ClassNode | Prism::ModuleNode | Prism::SingletonClassNode) -> void
#: (PrismTypes::anyScopeNode) -> void
def apply_class_annotations(node)
comments = node_rbs_comments(node)
return if comments.empty?
Expand Down Expand Up @@ -324,7 +324,7 @@ def apply_member_annotations(annotations, sig)
end
end

#: (Prism::ClassNode | Prism::ModuleNode | Prism::SingletonClassNode, Regexp) -> bool
#: (PrismTypes::anyScopeNode, Regexp) -> bool
def already_extends?(node, constant_regex)
node.child_nodes.any? do |c|
next false unless c.is_a?(Prism::CallNode)
Expand Down
4 changes: 2 additions & 2 deletions lib/spoom/sorbet/translate/sorbet_sigs_to_rbs_comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def visit_constant_write_node(node)

private

#: (Prism::ClassNode | Prism::ModuleNode | Prism::SingletonClassNode) { -> void } -> void
#: (PrismTypes::anyScopeNode) { -> void } -> void
def visit_scope(node, &block)
old_class_annotations = @class_annotations
@class_annotations = []
Expand Down Expand Up @@ -229,7 +229,7 @@ def visit_extend(node)
end
end

#: (Prism::ClassNode | Prism::ModuleNode | Prism::SingletonClassNode, Prism::CallNode) -> void
#: (PrismTypes::anyScopeNode, Prism::CallNode) -> void
def apply_class_annotation(parent, node)
unless node.message == "abstract!" || node.message == "interface!" || node.message == "sealed!" ||
node.message == "final!" || node.message == "requires_ancestor"
Expand Down
2 changes: 2 additions & 0 deletions rbi/spoom.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,8 @@ class Spoom::Printer
def printt; end
end

module Spoom::PrismTypes; end
Spoom::PrismTypes::AnyScopeNode = T.type_alias { T.any(::Prism::ClassNode, ::Prism::ModuleNode, ::Prism::SingletonClassNode) }
module Spoom::RBS; end
class Spoom::RBS::Annotation < ::Spoom::RBS::Comment; end

Expand Down
Loading