spoom 1.8.3 → 1.8.4
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/cli/srb/bump.rb +9 -1
- data/lib/spoom/cli/srb/sigs.rb +5 -0
- data/lib/spoom/cli/srb/tc.rb +5 -1
- data/lib/spoom/sorbet/errors.rb +39 -3
- data/lib/spoom/sorbet/translate/sorbet_sigs_to_rbs_comments.rb +21 -6
- data/lib/spoom/sorbet/translate.rb +6 -1
- data/lib/spoom/version.rb +1 -1
- data/rbi/spoom.rbi +32 -4
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6f138cb37a9cdcc10a7195440a948f6f9a3d2225ac032e2179823cf327b3d803
|
|
4
|
+
data.tar.gz: 9d8b55599e6de489d29362353f9ac3802b12ad85b6e9e34b40c09b07127ace47
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 708cb8b80b385e27c7d5a3e9cc05fbc475df994977a3cbf3ef4a1ea2cf592c91376bf9f1000aa7991ed0c154bb0e3ecc5120bd5ab01c94ca6e20a9a1bac98322
|
|
7
|
+
data.tar.gz: 262a4f6b42009e39c91a6e312ed54aba0056e6dd71d5ce136448c4f1343ee1037159a13ebb77d6f68113d64db7ebc3de61bad289440f0fa8b5efcca5e3444ee6
|
data/lib/spoom/cli/srb/bump.rb
CHANGED
|
@@ -135,6 +135,10 @@ module Spoom
|
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
if result.status
|
|
138
|
+
parse_result = Sorbet::Errors::Parser.parse_result(result.err, error_url_base: error_url_base)
|
|
139
|
+
parse_result.warnings.each do |warning|
|
|
140
|
+
say_error(warning, status: nil, nl: false)
|
|
141
|
+
end
|
|
138
142
|
Sorbet::Sigils.change_sigil_in_files(files_to_bump, to) unless dry
|
|
139
143
|
print_changes(files_to_bump, command: cmd, from: from, to: to, dry: dry, path: exec_path)
|
|
140
144
|
exit(files_to_bump.empty?)
|
|
@@ -147,7 +151,11 @@ module Spoom
|
|
|
147
151
|
exit(1)
|
|
148
152
|
end
|
|
149
153
|
|
|
150
|
-
|
|
154
|
+
parse_result = Sorbet::Errors::Parser.parse_result(result.err, error_url_base: error_url_base)
|
|
155
|
+
parse_result.warnings.each do |warning|
|
|
156
|
+
say_error(warning, status: nil, nl: false)
|
|
157
|
+
end
|
|
158
|
+
errors = parse_result.errors
|
|
151
159
|
|
|
152
160
|
all_files = errors.flat_map do |err|
|
|
153
161
|
[err.file, *err.files_from_error_sections]
|
data/lib/spoom/cli/srb/sigs.rb
CHANGED
|
@@ -17,6 +17,10 @@ module Spoom
|
|
|
17
17
|
aliases: :p,
|
|
18
18
|
desc: "Use positional names when translating from RBI to RBS",
|
|
19
19
|
default: true
|
|
20
|
+
option :preserve_multiline_signatures,
|
|
21
|
+
type: :boolean,
|
|
22
|
+
desc: "Preserve multiline sig formatting when translating from RBI to RBS",
|
|
23
|
+
default: true
|
|
20
24
|
option :include_rbi_files, type: :boolean, desc: "Include RBI files", default: false
|
|
21
25
|
option :max_line_length, type: :numeric, desc: "Max line length (pass 0 to disable)", default: 120
|
|
22
26
|
option :translate_generics, type: :boolean, desc: "Translate generics", default: false
|
|
@@ -53,6 +57,7 @@ module Spoom
|
|
|
53
57
|
contents,
|
|
54
58
|
file: file,
|
|
55
59
|
positional_names: options[:positional_names],
|
|
60
|
+
preserve_multiline_signatures: options[:preserve_multiline_signatures],
|
|
56
61
|
max_line_length: max_line_length,
|
|
57
62
|
translate_generics: options[:translate_generics],
|
|
58
63
|
translate_helpers: options[:translate_helpers],
|
data/lib/spoom/cli/srb/tc.rb
CHANGED
|
@@ -73,7 +73,11 @@ module Spoom
|
|
|
73
73
|
exit(1)
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
parse_result = Spoom::Sorbet::Errors::Parser.parse_result(result.err, error_url_base: error_url_base)
|
|
77
|
+
parse_result.warnings.each do |warning|
|
|
78
|
+
say_error(warning, status: nil, nl: false)
|
|
79
|
+
end
|
|
80
|
+
errors = parse_result.errors
|
|
77
81
|
errors_count = errors.size
|
|
78
82
|
|
|
79
83
|
errors = errors.select { |e| e.code == code } if code
|
data/lib/spoom/sorbet/errors.rb
CHANGED
|
@@ -56,22 +56,35 @@ module Spoom
|
|
|
56
56
|
] #: Array[String]
|
|
57
57
|
|
|
58
58
|
class << self
|
|
59
|
+
# Used when only Sorbet errors are needed and leading stderr warnings can be ignored.
|
|
59
60
|
#: (String output, ?error_url_base: String) -> Array[Error]
|
|
60
61
|
def parse_string(output, error_url_base: DEFAULT_ERROR_URL_BASE)
|
|
62
|
+
parse_result(output, error_url_base: error_url_base).errors
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Used when callers need both parsed Sorbet errors and leading stderr warnings.
|
|
66
|
+
#: (String output, ?error_url_base: String) -> ParseResult
|
|
67
|
+
def parse_result(output, error_url_base: DEFAULT_ERROR_URL_BASE)
|
|
61
68
|
parser = Spoom::Sorbet::Errors::Parser.new(error_url_base: error_url_base)
|
|
62
|
-
parser.
|
|
69
|
+
parser.parse_result(output)
|
|
63
70
|
end
|
|
64
71
|
end
|
|
65
72
|
|
|
66
73
|
#: (?error_url_base: String) -> void
|
|
67
74
|
def initialize(error_url_base: DEFAULT_ERROR_URL_BASE)
|
|
68
75
|
@errors = [] #: Array[Error]
|
|
76
|
+
@warnings = [] #: Array[String]
|
|
69
77
|
@error_line_match_regex = error_line_match_regexp(error_url_base) #: Regexp
|
|
70
78
|
@current_error = nil #: Error?
|
|
71
79
|
end
|
|
72
80
|
|
|
73
81
|
#: (String output) -> Array[Error]
|
|
74
82
|
def parse(output)
|
|
83
|
+
parse_result(output).errors
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
#: (String output) -> ParseResult
|
|
87
|
+
def parse_result(output)
|
|
75
88
|
output.each_line do |line|
|
|
76
89
|
break if /^No errors! Great job\./.match?(line)
|
|
77
90
|
break if /^Errors: /.match?(line)
|
|
@@ -85,10 +98,14 @@ module Spoom
|
|
|
85
98
|
next
|
|
86
99
|
end
|
|
87
100
|
|
|
88
|
-
|
|
101
|
+
if @current_error
|
|
102
|
+
append_error(line)
|
|
103
|
+
else
|
|
104
|
+
append_warning(line)
|
|
105
|
+
end
|
|
89
106
|
end
|
|
90
107
|
close_error if @current_error
|
|
91
|
-
@errors
|
|
108
|
+
ParseResult.new(@errors, @warnings)
|
|
92
109
|
end
|
|
93
110
|
|
|
94
111
|
private
|
|
@@ -144,6 +161,11 @@ module Spoom
|
|
|
144
161
|
end
|
|
145
162
|
@current_error.more << line
|
|
146
163
|
end
|
|
164
|
+
|
|
165
|
+
#: (String warning) -> void
|
|
166
|
+
def append_warning(warning)
|
|
167
|
+
@warnings << warning
|
|
168
|
+
end
|
|
147
169
|
end
|
|
148
170
|
|
|
149
171
|
class Error
|
|
@@ -214,6 +236,20 @@ module Spoom
|
|
|
214
236
|
testcase_element
|
|
215
237
|
end
|
|
216
238
|
end
|
|
239
|
+
|
|
240
|
+
class ParseResult
|
|
241
|
+
#: Array[Error]
|
|
242
|
+
attr_reader :errors
|
|
243
|
+
|
|
244
|
+
#: Array[String]
|
|
245
|
+
attr_reader :warnings
|
|
246
|
+
|
|
247
|
+
#: (Array[Error] errors, Array[String] warnings) -> void
|
|
248
|
+
def initialize(errors, warnings)
|
|
249
|
+
@errors = errors
|
|
250
|
+
@warnings = warnings
|
|
251
|
+
end
|
|
252
|
+
end
|
|
217
253
|
end
|
|
218
254
|
end
|
|
219
255
|
end
|
|
@@ -11,6 +11,7 @@ module Spoom
|
|
|
11
11
|
#| String,
|
|
12
12
|
#| file: String,
|
|
13
13
|
#| positional_names: bool,
|
|
14
|
+
#| ?preserve_multiline_signatures: bool,
|
|
14
15
|
#| ?max_line_length: Integer?,
|
|
15
16
|
#| ?translate_generics: bool,
|
|
16
17
|
#| ?translate_helpers: bool,
|
|
@@ -20,6 +21,7 @@ module Spoom
|
|
|
20
21
|
ruby_contents,
|
|
21
22
|
file:,
|
|
22
23
|
positional_names:,
|
|
24
|
+
preserve_multiline_signatures: true,
|
|
23
25
|
max_line_length: nil,
|
|
24
26
|
translate_generics: true,
|
|
25
27
|
translate_helpers: true,
|
|
@@ -34,6 +36,8 @@ module Spoom
|
|
|
34
36
|
@extend_t_helpers = [] #: Array[Prism::CallNode]
|
|
35
37
|
@extend_t_generics = [] #: Array[Prism::CallNode]
|
|
36
38
|
@seen_mixes_in_class_methods = false #: bool
|
|
39
|
+
|
|
40
|
+
@preserve_multiline_signatures = preserve_multiline_signatures
|
|
37
41
|
@max_line_length = max_line_length #: Integer?
|
|
38
42
|
|
|
39
43
|
@translate_generics = translate_generics #: bool
|
|
@@ -75,7 +79,12 @@ module Spoom
|
|
|
75
79
|
last_sigs.each do |node, sig|
|
|
76
80
|
next if sig.is_abstract && !@translate_abstract_methods
|
|
77
81
|
|
|
78
|
-
|
|
82
|
+
preserve_multiline_signatures = !!(@preserve_multiline_signatures && sig.loc&.multiline?)
|
|
83
|
+
|
|
84
|
+
out = rbs_print(
|
|
85
|
+
node.location.start_column,
|
|
86
|
+
preserve_multiline_signatures: preserve_multiline_signatures,
|
|
87
|
+
) do |printer|
|
|
79
88
|
printer.print_method_sig(rbi_node, sig)
|
|
80
89
|
end
|
|
81
90
|
@rewriter << Source::Replace.new(node.location.start_offset, node.location.end_offset, out)
|
|
@@ -180,7 +189,7 @@ module Spoom
|
|
|
180
189
|
return unless sorbet_sig?(node)
|
|
181
190
|
|
|
182
191
|
builder = RBI::Parser::SigBuilder.new(@ruby_contents, file: @file)
|
|
183
|
-
builder.current.loc = node.location
|
|
192
|
+
builder.current.loc = RBI::Loc.from_prism(@file, node.location)
|
|
184
193
|
builder.visit_call_node(node)
|
|
185
194
|
builder.current.comments = []
|
|
186
195
|
|
|
@@ -204,7 +213,7 @@ module Spoom
|
|
|
204
213
|
rbi_node = builder.tree.nodes.first #: as RBI::Attr
|
|
205
214
|
|
|
206
215
|
last_sigs.each do |node, sig|
|
|
207
|
-
out = rbs_print(node.location.start_column) do |printer|
|
|
216
|
+
out = rbs_print(node.location.start_column, preserve_multiline_signatures: false) do |printer|
|
|
208
217
|
printer.print_attr_sig(rbi_node, sig)
|
|
209
218
|
end
|
|
210
219
|
@rewriter << Source::Replace.new(node.location.start_offset, node.location.end_offset, out)
|
|
@@ -387,10 +396,16 @@ module Spoom
|
|
|
387
396
|
last_sigs
|
|
388
397
|
end
|
|
389
398
|
|
|
390
|
-
#: (Integer) { (RBI::RBSPrinter) -> void } -> String
|
|
391
|
-
def rbs_print(indent, &block)
|
|
399
|
+
#: (Integer, preserve_multiline_signatures: bool) { (RBI::RBSPrinter) -> void } -> String
|
|
400
|
+
def rbs_print(indent, preserve_multiline_signatures:, &block)
|
|
392
401
|
out = StringIO.new
|
|
393
|
-
|
|
402
|
+
|
|
403
|
+
p = RBI::RBSPrinter.new(
|
|
404
|
+
out: out,
|
|
405
|
+
positional_names: @positional_names,
|
|
406
|
+
max_line_length: @max_line_length,
|
|
407
|
+
force_multiline_signatures: preserve_multiline_signatures,
|
|
408
|
+
)
|
|
394
409
|
block.call(p)
|
|
395
410
|
string = out.string
|
|
396
411
|
|
|
@@ -30,13 +30,17 @@ module Spoom
|
|
|
30
30
|
#| String,
|
|
31
31
|
#| file: String,
|
|
32
32
|
#| ?positional_names: bool,
|
|
33
|
+
#| ?preserve_multiline_signatures: bool,
|
|
33
34
|
#| ?max_line_length: Integer?,
|
|
34
35
|
#| ?translate_generics: bool,
|
|
35
36
|
#| ?translate_helpers: bool,
|
|
36
37
|
#| ?translate_abstract_methods: bool
|
|
37
38
|
#| ) -> String
|
|
38
39
|
def sorbet_sigs_to_rbs_comments(
|
|
39
|
-
ruby_contents, file:,
|
|
40
|
+
ruby_contents, file:,
|
|
41
|
+
positional_names: true,
|
|
42
|
+
preserve_multiline_signatures: true,
|
|
43
|
+
max_line_length: nil,
|
|
40
44
|
translate_generics: true,
|
|
41
45
|
translate_helpers: true,
|
|
42
46
|
translate_abstract_methods: true
|
|
@@ -45,6 +49,7 @@ module Spoom
|
|
|
45
49
|
ruby_contents,
|
|
46
50
|
file: file,
|
|
47
51
|
positional_names: positional_names,
|
|
52
|
+
preserve_multiline_signatures: preserve_multiline_signatures,
|
|
48
53
|
max_line_length: max_line_length,
|
|
49
54
|
translate_generics: translate_generics,
|
|
50
55
|
translate_helpers: translate_helpers,
|
data/lib/spoom/version.rb
CHANGED
data/rbi/spoom.rbi
CHANGED
|
@@ -2753,6 +2753,17 @@ class Spoom::Sorbet::Errors::Error
|
|
|
2753
2753
|
def to_s; end
|
|
2754
2754
|
end
|
|
2755
2755
|
|
|
2756
|
+
class Spoom::Sorbet::Errors::ParseResult
|
|
2757
|
+
sig { params(errors: T::Array[::Spoom::Sorbet::Errors::Error], warnings: T::Array[::String]).void }
|
|
2758
|
+
def initialize(errors, warnings); end
|
|
2759
|
+
|
|
2760
|
+
sig { returns(T::Array[::Spoom::Sorbet::Errors::Error]) }
|
|
2761
|
+
def errors; end
|
|
2762
|
+
|
|
2763
|
+
sig { returns(T::Array[::String]) }
|
|
2764
|
+
def warnings; end
|
|
2765
|
+
end
|
|
2766
|
+
|
|
2756
2767
|
class Spoom::Sorbet::Errors::Parser
|
|
2757
2768
|
sig { params(error_url_base: ::String).void }
|
|
2758
2769
|
def initialize(error_url_base: T.unsafe(nil)); end
|
|
@@ -2760,11 +2771,17 @@ class Spoom::Sorbet::Errors::Parser
|
|
|
2760
2771
|
sig { params(output: ::String).returns(T::Array[::Spoom::Sorbet::Errors::Error]) }
|
|
2761
2772
|
def parse(output); end
|
|
2762
2773
|
|
|
2774
|
+
sig { params(output: ::String).returns(::Spoom::Sorbet::Errors::ParseResult) }
|
|
2775
|
+
def parse_result(output); end
|
|
2776
|
+
|
|
2763
2777
|
private
|
|
2764
2778
|
|
|
2765
2779
|
sig { params(line: ::String).void }
|
|
2766
2780
|
def append_error(line); end
|
|
2767
2781
|
|
|
2782
|
+
sig { params(warning: ::String).void }
|
|
2783
|
+
def append_warning(warning); end
|
|
2784
|
+
|
|
2768
2785
|
sig { void }
|
|
2769
2786
|
def close_error; end
|
|
2770
2787
|
|
|
@@ -2778,6 +2795,9 @@ class Spoom::Sorbet::Errors::Parser
|
|
|
2778
2795
|
def open_error(error); end
|
|
2779
2796
|
|
|
2780
2797
|
class << self
|
|
2798
|
+
sig { params(output: ::String, error_url_base: ::String).returns(::Spoom::Sorbet::Errors::ParseResult) }
|
|
2799
|
+
def parse_result(output, error_url_base: T.unsafe(nil)); end
|
|
2800
|
+
|
|
2781
2801
|
sig { params(output: ::String, error_url_base: ::String).returns(T::Array[::Spoom::Sorbet::Errors::Error]) }
|
|
2782
2802
|
def parse_string(output, error_url_base: T.unsafe(nil)); end
|
|
2783
2803
|
end
|
|
@@ -2929,13 +2949,14 @@ module Spoom::Sorbet::Translate
|
|
|
2929
2949
|
ruby_contents: ::String,
|
|
2930
2950
|
file: ::String,
|
|
2931
2951
|
positional_names: T::Boolean,
|
|
2952
|
+
preserve_multiline_signatures: T::Boolean,
|
|
2932
2953
|
max_line_length: T.nilable(::Integer),
|
|
2933
2954
|
translate_generics: T::Boolean,
|
|
2934
2955
|
translate_helpers: T::Boolean,
|
|
2935
2956
|
translate_abstract_methods: T::Boolean
|
|
2936
2957
|
).returns(::String)
|
|
2937
2958
|
end
|
|
2938
|
-
def sorbet_sigs_to_rbs_comments(ruby_contents, file:, positional_names: T.unsafe(nil), max_line_length: T.unsafe(nil), translate_generics: T.unsafe(nil), translate_helpers: T.unsafe(nil), translate_abstract_methods: T.unsafe(nil)); end
|
|
2959
|
+
def sorbet_sigs_to_rbs_comments(ruby_contents, file:, positional_names: T.unsafe(nil), preserve_multiline_signatures: T.unsafe(nil), max_line_length: T.unsafe(nil), translate_generics: T.unsafe(nil), translate_helpers: T.unsafe(nil), translate_abstract_methods: T.unsafe(nil)); end
|
|
2939
2960
|
|
|
2940
2961
|
sig { params(ruby_contents: ::String, file: ::String).returns(::String) }
|
|
2941
2962
|
def strip_sorbet_sigs(ruby_contents, file:); end
|
|
@@ -3304,13 +3325,14 @@ class Spoom::Sorbet::Translate::SorbetSigsToRBSComments < ::Spoom::Sorbet::Trans
|
|
|
3304
3325
|
ruby_contents: ::String,
|
|
3305
3326
|
file: ::String,
|
|
3306
3327
|
positional_names: T::Boolean,
|
|
3328
|
+
preserve_multiline_signatures: T::Boolean,
|
|
3307
3329
|
max_line_length: T.nilable(::Integer),
|
|
3308
3330
|
translate_generics: T::Boolean,
|
|
3309
3331
|
translate_helpers: T::Boolean,
|
|
3310
3332
|
translate_abstract_methods: T::Boolean
|
|
3311
3333
|
).void
|
|
3312
3334
|
end
|
|
3313
|
-
def initialize(ruby_contents, file:, positional_names:, max_line_length: T.unsafe(nil), translate_generics: T.unsafe(nil), translate_helpers: T.unsafe(nil), translate_abstract_methods: T.unsafe(nil)); end
|
|
3335
|
+
def initialize(ruby_contents, file:, positional_names:, preserve_multiline_signatures: T.unsafe(nil), max_line_length: T.unsafe(nil), translate_generics: T.unsafe(nil), translate_helpers: T.unsafe(nil), translate_abstract_methods: T.unsafe(nil)); end
|
|
3314
3336
|
|
|
3315
3337
|
sig { override.params(node: ::Prism::CallNode).void }
|
|
3316
3338
|
def visit_call_node(node); end
|
|
@@ -3355,8 +3377,14 @@ class Spoom::Sorbet::Translate::SorbetSigsToRBSComments < ::Spoom::Sorbet::Trans
|
|
|
3355
3377
|
sig { void }
|
|
3356
3378
|
def delete_extend_t_helpers; end
|
|
3357
3379
|
|
|
3358
|
-
sig
|
|
3359
|
-
|
|
3380
|
+
sig do
|
|
3381
|
+
params(
|
|
3382
|
+
indent: ::Integer,
|
|
3383
|
+
preserve_multiline_signatures: T::Boolean,
|
|
3384
|
+
block: T.proc.params(arg0: ::RBI::RBSPrinter).void
|
|
3385
|
+
).returns(::String)
|
|
3386
|
+
end
|
|
3387
|
+
def rbs_print(indent, preserve_multiline_signatures:, &block); end
|
|
3360
3388
|
|
|
3361
3389
|
sig { params(node: ::Prism::CallNode).void }
|
|
3362
3390
|
def visit_attr(node); end
|
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.8.
|
|
4
|
+
version: 1.8.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexandre Terrasa
|
|
@@ -85,14 +85,14 @@ dependencies:
|
|
|
85
85
|
requirements:
|
|
86
86
|
- - ">="
|
|
87
87
|
- !ruby/object:Gem::Version
|
|
88
|
-
version: 0.3.
|
|
88
|
+
version: 0.3.15
|
|
89
89
|
type: :runtime
|
|
90
90
|
prerelease: false
|
|
91
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
92
92
|
requirements:
|
|
93
93
|
- - ">="
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
|
-
version: 0.3.
|
|
95
|
+
version: 0.3.15
|
|
96
96
|
- !ruby/object:Gem::Dependency
|
|
97
97
|
name: rbs
|
|
98
98
|
requirement: !ruby/object:Gem::Requirement
|