Skip to content

Commit 3d39b93

Browse files
committedMar 6, 2025
WIP
1 parent 8d5d7e8 commit 3d39b93

13 files changed

+4593
-5086
lines changed
 

‎Gemfile

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ source "https://rubygems.org"
55

66
gemspec
77

8-
gem "rbi", github: "Shopify/rbi", branch: "at-rbs-printer-names"
9-
108
group :development do
119
gem "debug"
1210
gem "rubocop-shopify", require: false

‎Gemfile.lock

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
GIT
2-
remote: https://github.com/Shopify/rbi.git
3-
revision: e6265fd9dfb38db414d2e7eb8cd69d565933410f
4-
branch: at-rbs-printer-names
5-
specs:
6-
rbi (0.2.4)
7-
prism (~> 1.0)
8-
sorbet-runtime (>= 0.5.9204)
9-
101
PATH
112
remote: .
123
specs:
134
spoom (1.5.4)
145
erubi (>= 1.10.0)
156
prism (>= 0.28.0)
16-
rbi (>= 0.2.3)
7+
rbi (>= 0.2.4)
178
sorbet-static-and-runtime (>= 0.5.10187)
189
thor (>= 0.19.2)
1910

@@ -53,6 +44,9 @@ GEM
5344
racc (1.8.1)
5445
rainbow (3.1.1)
5546
rake (13.2.1)
47+
rbi (0.2.4)
48+
prism (~> 1.0)
49+
sorbet-runtime (>= 0.5.9204)
5650
rdoc (6.10.0)
5751
psych (>= 4.0.0)
5852
regexp_parser (2.9.2)
@@ -113,7 +107,6 @@ DEPENDENCIES
113107
minitest (~> 5.0)
114108
minitest-reporters
115109
rake (~> 13.2.1)
116-
rbi!
117110
rubocop-shopify
118111
rubocop-sorbet
119112
spoom!

‎lib/spoom/cli/srb/sigs.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Sigs < Thor
1313
desc "translate", "Translate signatures from/to RBI and RBS"
1414
option :from, type: :string, aliases: :f, desc: "From format", enum: ["rbi"], default: "rbi"
1515
option :to, type: :string, aliases: :t, desc: "To format", enum: ["rbs"], default: "rbs"
16+
option :positional_names, type: :boolean, aliases: :p, desc: "Use positional names", default: true
1617
def translate(*paths)
1718
from = options[:from]
1819
to = options[:to]
@@ -22,7 +23,7 @@ def translate(*paths)
2223
"in `#{files.size}` file#{files.size == 1 ? "" : "s"}...\n\n")
2324

2425
transformed_files = transform_files(files) do |_file, contents|
25-
Spoom::Sorbet::Sigs.rbi_to_rbs(contents)
26+
Spoom::Sorbet::Sigs.rbi_to_rbs(contents, positional_names: options[:positional_names])
2627
end
2728

2829
say("Translated signatures in `#{transformed_files}` file#{transformed_files == 1 ? "" : "s"}.")

‎lib/spoom/sorbet/sigs.rb

+11-10
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def strip(ruby_contents)
2121
lines.join
2222
end
2323

24-
#: (String ruby_contents) -> String
25-
def rbi_to_rbs(ruby_contents)
24+
#: (String ruby_contents, positional_names: bool) -> String
25+
def rbi_to_rbs(ruby_contents, positional_names: true)
2626
ruby_contents = ruby_contents.dup
2727
sigs = collect_sigs(ruby_contents)
2828

@@ -36,7 +36,8 @@ def rbi_to_rbs(ruby_contents)
3636
sig.loc&.end_line&.pred,
3737
T.must(sig.loc).end_column,
3838
)
39-
ruby_contents[start_index...end_index] = SigTranslator.translate(sig, node)
39+
ruby_contents[start_index...end_index] =
40+
SigTranslator.translate(sig, node, positional_names: positional_names)
4041
end
4142

4243
ruby_contents
@@ -87,13 +88,13 @@ class SigTranslator
8788
class << self
8889
extend T::Sig
8990

90-
#: (RBI::Sig sig, (RBI::Method | RBI::Attr) node) -> String
91-
def translate(sig, node)
91+
#: (RBI::Sig sig, (RBI::Method | RBI::Attr) node, positional_names: bool) -> String
92+
def translate(sig, node, positional_names: true)
9293
case node
9394
when RBI::Method
94-
translate_method_sig(sig, node)
95+
translate_method_sig(sig, node, positional_names: positional_names)
9596
when RBI::Attr
96-
translate_attr_sig(sig, node)
97+
translate_attr_sig(sig, node, positional_names: positional_names)
9798
end
9899
end
99100

@@ -134,10 +135,10 @@ def translate_method_sig(sig, node, positional_names: true)
134135
out.string
135136
end
136137

137-
#: (RBI::Sig sig, RBI::Attr node) -> String
138-
def translate_attr_sig(sig, node)
138+
#: (RBI::Sig sig, RBI::Attr node, positional_names: bool) -> String
139+
def translate_attr_sig(sig, node, positional_names: true)
139140
out = StringIO.new
140-
p = RBI::RBSPrinter.new(out: out)
141+
p = RBI::RBSPrinter.new(out: out, positional_names: positional_names)
141142
p.print_attr_sig(node, sig)
142143
"#: #{out.string}"
143144
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)
Failed to load comments.