spoom 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebcf07d1aa065b643270105e211a05e9698befb8a67cf307c87c2fb957cd69fa
4
- data.tar.gz: 4de71559b8d0812d7ab2456404cdf1ec840bd7031c7138a04e3233208ab8f827
3
+ metadata.gz: 3c9b64402b943d03196b4ac55fc9f9582c635e20b50639ea631b345149e02fa3
4
+ data.tar.gz: 9e1720b82a26ac68cd91125bf05605f7964926829a06d9b9a7b2ac3bb4881e26
5
5
  SHA512:
6
- metadata.gz: ffd0520b3dcce46ea2ee2e00f4f7de974cedf21eddc706bed67616696f3f23406cbee80aeb62715c7dbfa7562a88486e21b6424b84b62d9f9a13b0a2d2f287b9
7
- data.tar.gz: 7a7256c1a7114e46254d0cd648306ee8b1e9565522671318c710af33a571461da14b40e0d99405e63a12481f05c29b35bc3d0e660c8e7129928f1a9c34264ca9
6
+ metadata.gz: d8138e2c64f4615b21f3b83b6c42013f6559a51ea173bc1086d8aae44c300a0596338826e3f03653c9ed39ead2fc799bec901b8cfac684cafb341981aeeea3e6
7
+ data.tar.gz: 38140e0e9cda06b563595a1616622f81f4860a8f3f9fbf2bafd2111879f56349b65c2865769b25035902dedc5574ef1267ae1b14cd05517867d20ef3296f52e1
@@ -12,6 +12,11 @@ module Spoom
12
12
  desc "translate", "Translate signatures from/to RBI and RBS"
13
13
  option :from, type: :string, aliases: :f, desc: "From format", enum: ["rbi", "rbs"], default: "rbi"
14
14
  option :to, type: :string, aliases: :t, desc: "To format", enum: ["rbi", "rbs"], default: "rbs"
15
+ option :positional_names,
16
+ type: :boolean,
17
+ aliases: :p,
18
+ desc: "Use positional names when translating from RBI to RBS",
19
+ default: true
15
20
  def translate(*paths)
16
21
  from = options[:from]
17
22
  to = options[:to]
@@ -29,7 +34,7 @@ module Spoom
29
34
  case from
30
35
  when "rbi"
31
36
  transformed_files = transform_files(files) do |_file, contents|
32
- Spoom::Sorbet::Sigs.rbi_to_rbs(contents)
37
+ Spoom::Sorbet::Sigs.rbi_to_rbs(contents, positional_names: options[:positional_names])
33
38
  end
34
39
  when "rbs"
35
40
  transformed_files = transform_files(files) do |_file, contents|
@@ -20,8 +20,8 @@ module Spoom
20
20
  lines.join
21
21
  end
22
22
 
23
- #: (String ruby_contents) -> String
24
- def rbi_to_rbs(ruby_contents)
23
+ #: (String ruby_contents, positional_names: bool) -> String
24
+ def rbi_to_rbs(ruby_contents, positional_names: true)
25
25
  ruby_contents = ruby_contents.dup
26
26
  sigs = collect_sorbet_sigs(ruby_contents)
27
27
 
@@ -35,7 +35,8 @@ module Spoom
35
35
  sig.loc&.end_line&.pred,
36
36
  T.must(sig.loc).end_column,
37
37
  )
38
- ruby_contents[start_index...end_index] = RBIToRBSTranslator.translate(sig, node)
38
+ rbs = RBIToRBSTranslator.translate(sig, node, positional_names: positional_names)
39
+ ruby_contents[start_index...end_index] = rbs
39
40
  end
40
41
 
41
42
  ruby_contents
@@ -56,7 +57,10 @@ module Spoom
56
57
  rbs_comment.loc&.end_line&.pred,
57
58
  T.must(rbs_comment.loc).end_column,
58
59
  )
59
- ruby_contents[start_index...end_index] = RBSToRBITranslator.translate(rbs_comment, node)
60
+ rbi = RBSToRBITranslator.translate(rbs_comment, node)
61
+ next unless rbi
62
+
63
+ ruby_contents[start_index...end_index] = rbi
60
64
  end
61
65
 
62
66
  ruby_contents
@@ -118,22 +122,22 @@ module Spoom
118
122
 
119
123
  class RBIToRBSTranslator
120
124
  class << self
121
- #: (RBI::Sig sig, (RBI::Method | RBI::Attr) node) -> String
122
- def translate(sig, node)
125
+ #: (RBI::Sig sig, (RBI::Method | RBI::Attr) node, positional_names: bool) -> String
126
+ def translate(sig, node, positional_names: true)
123
127
  case node
124
128
  when RBI::Method
125
- translate_method_sig(sig, node)
129
+ translate_method_sig(sig, node, positional_names: positional_names)
126
130
  when RBI::Attr
127
- translate_attr_sig(sig, node)
131
+ translate_attr_sig(sig, node, positional_names: positional_names)
128
132
  end
129
133
  end
130
134
 
131
135
  private
132
136
 
133
- #: (RBI::Sig sig, RBI::Method node) -> String
134
- def translate_method_sig(sig, node)
137
+ #: (RBI::Sig sig, RBI::Method node, positional_names: bool) -> String
138
+ def translate_method_sig(sig, node, positional_names: true)
135
139
  out = StringIO.new
136
- p = RBI::RBSPrinter.new(out: out, indent: sig.loc&.begin_column)
140
+ p = RBI::RBSPrinter.new(out: out, indent: sig.loc&.begin_column, positional_names: positional_names)
137
141
 
138
142
  if node.sigs.any?(&:is_final)
139
143
  p.printn("# @final")
@@ -165,10 +169,10 @@ module Spoom
165
169
  out.string
166
170
  end
167
171
 
168
- #: (RBI::Sig sig, RBI::Attr node) -> String
169
- def translate_attr_sig(sig, node)
172
+ #: (RBI::Sig sig, RBI::Attr node, positional_names: bool) -> String
173
+ def translate_attr_sig(sig, node, positional_names: true)
170
174
  out = StringIO.new
171
- p = RBI::RBSPrinter.new(out: out)
175
+ p = RBI::RBSPrinter.new(out: out, positional_names: positional_names)
172
176
  p.print_attr_sig(node, sig)
173
177
  "#: #{out.string}"
174
178
  end
@@ -179,7 +183,7 @@ module Spoom
179
183
  class << self
180
184
  extend T::Sig
181
185
 
182
- #: (RBI::RBSComment comment, (RBI::Method | RBI::Attr) node) -> String
186
+ #: (RBI::RBSComment comment, (RBI::Method | RBI::Attr) node) -> String?
183
187
  def translate(comment, node)
184
188
  case node
185
189
  when RBI::Method
@@ -187,6 +191,8 @@ module Spoom
187
191
  when RBI::Attr
188
192
  translate_attr_sig(comment, node)
189
193
  end
194
+ rescue RBS::ParsingError
195
+ nil
190
196
  end
191
197
 
192
198
  private
data/lib/spoom/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Spoom
5
- VERSION = "1.6.0"
5
+ VERSION = "1.6.1"
6
6
  end
data/rbi/spoom.rbi CHANGED
@@ -3417,8 +3417,8 @@ Spoom::Sorbet::Sigils::VALID_STRICTNESS = T.let(T.unsafe(nil), Array)
3417
3417
 
3418
3418
  class Spoom::Sorbet::Sigs
3419
3419
  class << self
3420
- sig { params(ruby_contents: ::String).returns(::String) }
3421
- def rbi_to_rbs(ruby_contents); end
3420
+ sig { params(ruby_contents: ::String, positional_names: T::Boolean).returns(::String) }
3421
+ def rbi_to_rbs(ruby_contents, positional_names: T.unsafe(nil)); end
3422
3422
 
3423
3423
  sig { params(ruby_contents: ::String).returns(::String) }
3424
3424
  def rbs_to_rbi(ruby_contents); end
@@ -3440,22 +3440,28 @@ class Spoom::Sorbet::Sigs::Error < ::Spoom::Error; end
3440
3440
 
3441
3441
  class Spoom::Sorbet::Sigs::RBIToRBSTranslator
3442
3442
  class << self
3443
- sig { params(sig: ::RBI::Sig, node: T.any(::RBI::Attr, ::RBI::Method)).returns(::String) }
3444
- def translate(sig, node); end
3443
+ sig do
3444
+ params(
3445
+ sig: ::RBI::Sig,
3446
+ node: T.any(::RBI::Attr, ::RBI::Method),
3447
+ positional_names: T::Boolean
3448
+ ).returns(::String)
3449
+ end
3450
+ def translate(sig, node, positional_names: T.unsafe(nil)); end
3445
3451
 
3446
3452
  private
3447
3453
 
3448
- sig { params(sig: ::RBI::Sig, node: ::RBI::Attr).returns(::String) }
3449
- def translate_attr_sig(sig, node); end
3454
+ sig { params(sig: ::RBI::Sig, node: ::RBI::Attr, positional_names: T::Boolean).returns(::String) }
3455
+ def translate_attr_sig(sig, node, positional_names: T.unsafe(nil)); end
3450
3456
 
3451
- sig { params(sig: ::RBI::Sig, node: ::RBI::Method).returns(::String) }
3452
- def translate_method_sig(sig, node); end
3457
+ sig { params(sig: ::RBI::Sig, node: ::RBI::Method, positional_names: T::Boolean).returns(::String) }
3458
+ def translate_method_sig(sig, node, positional_names: T.unsafe(nil)); end
3453
3459
  end
3454
3460
  end
3455
3461
 
3456
3462
  class Spoom::Sorbet::Sigs::RBSToRBITranslator
3457
3463
  class << self
3458
- sig { params(comment: ::RBI::RBSComment, node: T.any(::RBI::Attr, ::RBI::Method)).returns(::String) }
3464
+ sig { params(comment: ::RBI::RBSComment, node: T.any(::RBI::Attr, ::RBI::Method)).returns(T.nilable(::String)) }
3459
3465
  def translate(comment, node); end
3460
3466
 
3461
3467
  private
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spoom
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-11 00:00:00.000000000 Z
10
+ date: 2025-03-13 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler