spoom 1.7.5 → 1.7.7
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 +4 -4
- data/lib/spoom/rbs.rb +8 -0
- data/lib/spoom/sorbet/translate/sorbet_assertions_to_rbs_comments.rb +46 -5
- data/lib/spoom/version.rb +1 -1
- data/rbi/spoom.rbi +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dee74aa6f300c648be7b9c74808c1f24507e3c806a9fb80565f6bad3a84ca724
|
4
|
+
data.tar.gz: a6202c46d255610003479c753cd209a8511b5bc7511bcfe9d092e7619ed7d68a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed6f6fb93669b54ce54010fb657d8f3264e29e7c825382b49dbbc718aad8d48177392cc3ab89c9a2c669bf183c87653cb5c2682c222c311991cfaaca3f7e5088
|
7
|
+
data.tar.gz: b763bdbc1480b4e6290cd152190726855bd0c0347cfd582ba12d79e3d106703cf3117a471ff4493c7f579d1713260e3c7b423d2de633fafaacb3945b26ae37d4
|
data/lib/spoom/rbs.rb
CHANGED
@@ -75,9 +75,17 @@ module Spoom
|
|
75
75
|
|
76
76
|
continuation_comments = [] #: Array[Prism::Comment]
|
77
77
|
|
78
|
+
last_line = node.location.start_line
|
79
|
+
|
78
80
|
comments.each do |comment|
|
79
81
|
string = comment.slice
|
80
82
|
|
83
|
+
comment_line = comment.location.end_line
|
84
|
+
|
85
|
+
break if comment_line < last_line - 1
|
86
|
+
|
87
|
+
last_line = comment_line
|
88
|
+
|
81
89
|
if string.start_with?("# @")
|
82
90
|
string = string.delete_prefix("#").strip
|
83
91
|
res.annotations << Annotation.new(string, comment.location)
|
@@ -89,18 +89,26 @@ module Spoom
|
|
89
89
|
return false unless translatable_annotation?(node)
|
90
90
|
return false unless at_end_of_line?(node)
|
91
91
|
|
92
|
+
trailing_comment, comment_end_offset = extract_trailing_comment(node)
|
93
|
+
# If extract_trailing_comment returns nil when there's an RBS annotation, don't translate
|
94
|
+
return false if trailing_comment.nil? && has_rbs_annotation?(node)
|
95
|
+
|
92
96
|
value = T.must(node.arguments&.arguments&.first)
|
93
97
|
rbs_annotation = build_rbs_annotation(node)
|
94
98
|
|
95
99
|
start_offset = node.location.start_offset
|
96
|
-
|
100
|
+
# If there's a trailing comment, replace up to the end of the comment
|
101
|
+
# Otherwise, replace up to the end of the node
|
102
|
+
end_offset = comment_end_offset || node.location.end_offset
|
97
103
|
|
98
|
-
|
99
|
-
|
104
|
+
replacement = if node.name == :bind
|
105
|
+
"#{rbs_annotation}#{trailing_comment}"
|
100
106
|
else
|
101
|
-
|
107
|
+
"#{dedent_value(node, value)} #{rbs_annotation}#{trailing_comment}"
|
102
108
|
end
|
103
109
|
|
110
|
+
@rewriter << Source::Replace.new(start_offset, end_offset - 1, replacement)
|
111
|
+
|
104
112
|
true
|
105
113
|
end
|
106
114
|
|
@@ -166,7 +174,40 @@ module Spoom
|
|
166
174
|
def at_end_of_line?(node)
|
167
175
|
end_offset = node.location.end_offset
|
168
176
|
end_offset += 1 while (@ruby_bytes[end_offset] == " ".ord) && (end_offset < @ruby_bytes.size)
|
169
|
-
|
177
|
+
# Check if we're at a newline OR at the start of a comment
|
178
|
+
@ruby_bytes[end_offset] == LINE_BREAK || @ruby_bytes[end_offset] == "#".ord
|
179
|
+
end
|
180
|
+
|
181
|
+
# Check if the node has an RBS annotation comment (#:) after it
|
182
|
+
#: (Prism::Node) -> bool
|
183
|
+
def has_rbs_annotation?(node)
|
184
|
+
end_offset = node.location.end_offset
|
185
|
+
# Skip spaces
|
186
|
+
end_offset += 1 while (@ruby_bytes[end_offset] == " ".ord) && (end_offset < @ruby_bytes.size)
|
187
|
+
# Check if there's a comment starting with #:
|
188
|
+
@ruby_bytes[end_offset] == "#".ord && @ruby_bytes[end_offset + 1] == ":".ord
|
189
|
+
end
|
190
|
+
|
191
|
+
# Extract any trailing comment after the node
|
192
|
+
# Returns [comment_text, comment_end_offset] or [nil, nil] if no comment or RBS annotation
|
193
|
+
#: (Prism::Node) -> [String?, Integer?]
|
194
|
+
def extract_trailing_comment(node)
|
195
|
+
end_offset = node.location.end_offset
|
196
|
+
# Skip spaces
|
197
|
+
end_offset += 1 while (@ruby_bytes[end_offset] == " ".ord) && (end_offset < @ruby_bytes.size)
|
198
|
+
# Check if there's a comment
|
199
|
+
return [nil, nil] unless @ruby_bytes[end_offset] == "#".ord
|
200
|
+
|
201
|
+
# If it's an RBS annotation comment (#:), return nil to prevent translation
|
202
|
+
return [nil, nil] if @ruby_bytes[end_offset + 1] == ":".ord
|
203
|
+
|
204
|
+
# Find the end of the comment (end of line)
|
205
|
+
comment_start = end_offset
|
206
|
+
end_offset += 1 while @ruby_bytes[end_offset] != LINE_BREAK && end_offset < @ruby_bytes.size
|
207
|
+
|
208
|
+
# Extract the comment including the leading space and return the end offset
|
209
|
+
range = @ruby_bytes[comment_start...end_offset] #: as !nil
|
210
|
+
[" #{range.pack("C*")}", end_offset]
|
170
211
|
end
|
171
212
|
|
172
213
|
#: (Prism::Node, Prism::Node) -> String
|
data/lib/spoom/version.rb
CHANGED
data/rbi/spoom.rbi
CHANGED
@@ -2950,6 +2950,12 @@ class Spoom::Sorbet::Translate::SorbetAssertionsToRBSComments < ::Spoom::Sorbet:
|
|
2950
2950
|
sig { params(assign: ::Prism::Node, value: ::Prism::Node).returns(::String) }
|
2951
2951
|
def dedent_value(assign, value); end
|
2952
2952
|
|
2953
|
+
sig { params(node: ::Prism::Node).returns([T.nilable(::String), T.nilable(::Integer)]) }
|
2954
|
+
def extract_trailing_comment(node); end
|
2955
|
+
|
2956
|
+
sig { params(node: ::Prism::Node).returns(T::Boolean) }
|
2957
|
+
def has_rbs_annotation?(node); end
|
2958
|
+
|
2953
2959
|
sig { params(node: ::Prism::Node).returns(T::Boolean) }
|
2954
2960
|
def maybe_translate_assertion(node); end
|
2955
2961
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spoom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Terrasa
|
@@ -274,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
274
274
|
- !ruby/object:Gem::Version
|
275
275
|
version: '0'
|
276
276
|
requirements: []
|
277
|
-
rubygems_version: 3.
|
277
|
+
rubygems_version: 3.7.2
|
278
278
|
specification_version: 4
|
279
279
|
summary: Useful tools for Sorbet enthusiasts.
|
280
280
|
test_files: []
|