rbi 0.2.2 → 0.2.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/Gemfile +1 -1
- data/lib/rbi/formatter.rb +0 -3
- data/lib/rbi/model.rb +6 -3
- data/lib/rbi/parser.rb +16 -7
- data/lib/rbi/printer.rb +9 -1
- data/lib/rbi/rbs_printer.rb +70 -19
- data/lib/rbi/version.rb +1 -1
- metadata +3 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8f99c70643c9f05b1b7dda28cb2091654c1865b124b01a981fc4a3b6f59275f
|
4
|
+
data.tar.gz: 9d0b4626b14eced346dd4899cce76996137a84047f4b10142e01d0c35655b450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e02a6ffba6687475814388820be9ae352ec732fa288f2295af75959a0ad7b3032992fa6c17b4cb2b03cdcb26667c48b5038c7c4d04babe25be77e0404ff41880
|
7
|
+
data.tar.gz: 0dd7254c9b7ac5c204654bd71f1a26b6b8597e2c5b10a199c5e0ab40224d5444d38eaf4c1e1c4a2acb9c75e482464ef55b7419216dc2f02556d8c8b2317e0f84
|
data/Gemfile
CHANGED
@@ -10,7 +10,7 @@ group(:development, :test) do
|
|
10
10
|
gem("minitest")
|
11
11
|
gem("minitest-reporters")
|
12
12
|
gem("rake", "~> 13.2")
|
13
|
-
gem("rubocop", "~> 1.
|
13
|
+
gem("rubocop", "~> 1.70", require: false)
|
14
14
|
gem("rubocop-shopify", require: false)
|
15
15
|
gem("rubocop-sorbet", require: false)
|
16
16
|
gem("sorbet", ">= 0.5.9204", require: false)
|
data/lib/rbi/formatter.rb
CHANGED
data/lib/rbi/model.rb
CHANGED
@@ -261,7 +261,7 @@ module RBI
|
|
261
261
|
).void
|
262
262
|
end
|
263
263
|
def initialize(loc: nil, comments: [], &block)
|
264
|
-
super
|
264
|
+
super {}
|
265
265
|
block&.call(self)
|
266
266
|
end
|
267
267
|
|
@@ -1111,7 +1111,7 @@ module RBI
|
|
1111
1111
|
attr_accessor :return_type
|
1112
1112
|
|
1113
1113
|
sig { returns(T::Boolean) }
|
1114
|
-
attr_accessor :is_abstract, :is_override, :is_overridable, :is_final
|
1114
|
+
attr_accessor :is_abstract, :is_override, :is_overridable, :is_final, :allow_incompatible_override
|
1115
1115
|
|
1116
1116
|
sig { returns(T::Array[String]) }
|
1117
1117
|
attr_reader :type_params
|
@@ -1127,6 +1127,7 @@ module RBI
|
|
1127
1127
|
is_override: T::Boolean,
|
1128
1128
|
is_overridable: T::Boolean,
|
1129
1129
|
is_final: T::Boolean,
|
1130
|
+
allow_incompatible_override: T::Boolean,
|
1130
1131
|
type_params: T::Array[String],
|
1131
1132
|
checked: T.nilable(Symbol),
|
1132
1133
|
loc: T.nilable(Loc),
|
@@ -1141,6 +1142,7 @@ module RBI
|
|
1141
1142
|
is_override: false,
|
1142
1143
|
is_overridable: false,
|
1143
1144
|
is_final: false,
|
1145
|
+
allow_incompatible_override: false,
|
1144
1146
|
type_params: [],
|
1145
1147
|
checked: nil,
|
1146
1148
|
loc: nil,
|
@@ -1154,6 +1156,7 @@ module RBI
|
|
1154
1156
|
@is_override = is_override
|
1155
1157
|
@is_overridable = is_overridable
|
1156
1158
|
@is_final = is_final
|
1159
|
+
@allow_incompatible_override = allow_incompatible_override
|
1157
1160
|
@type_params = type_params
|
1158
1161
|
@checked = checked
|
1159
1162
|
block&.call(self)
|
@@ -1354,7 +1357,7 @@ module RBI
|
|
1354
1357
|
).void
|
1355
1358
|
end
|
1356
1359
|
def initialize(loc: nil, comments: [], &block)
|
1357
|
-
super
|
1360
|
+
super {}
|
1358
1361
|
block&.call(self)
|
1359
1362
|
end
|
1360
1363
|
|
data/lib/rbi/parser.rb
CHANGED
@@ -451,11 +451,6 @@ module RBI
|
|
451
451
|
loc: node_loc(node),
|
452
452
|
comments: node_comments(node),
|
453
453
|
)
|
454
|
-
else
|
455
|
-
raise ParseError.new(
|
456
|
-
"Unexpected token `#{node.message}` before `#{last_node&.string&.strip}`",
|
457
|
-
node_loc(node),
|
458
|
-
)
|
459
454
|
end
|
460
455
|
else
|
461
456
|
current_scope << parse_visibility(node.name.to_s, node)
|
@@ -722,8 +717,6 @@ module RBI
|
|
722
717
|
|
723
718
|
keyword_init = val == "true" if key == "keyword_init:"
|
724
719
|
end
|
725
|
-
else
|
726
|
-
raise ParseError.new("Unexpected node type `#{arg.class}`", node_loc(arg))
|
727
720
|
end
|
728
721
|
end
|
729
722
|
end
|
@@ -858,6 +851,22 @@ module RBI
|
|
858
851
|
end
|
859
852
|
when "override"
|
860
853
|
@current.is_override = true
|
854
|
+
|
855
|
+
args = node.arguments&.arguments
|
856
|
+
|
857
|
+
keywords_hash = args
|
858
|
+
&.grep(Prism::KeywordHashNode)
|
859
|
+
&.first
|
860
|
+
|
861
|
+
allow_incompatible_override = keywords_hash
|
862
|
+
&.elements
|
863
|
+
&.any? do |assoc|
|
864
|
+
assoc.is_a?(Prism::AssocNode) &&
|
865
|
+
node_string(assoc.key) == "allow_incompatible:" &&
|
866
|
+
node_string(assoc.value) == "true"
|
867
|
+
end
|
868
|
+
|
869
|
+
@current.allow_incompatible_override = !!allow_incompatible_override
|
861
870
|
when "overridable"
|
862
871
|
@current.is_overridable = true
|
863
872
|
when "params"
|
data/lib/rbi/printer.rb
CHANGED
@@ -721,7 +721,15 @@ module RBI
|
|
721
721
|
def sig_modifiers(node)
|
722
722
|
modifiers = T.let([], T::Array[String])
|
723
723
|
modifiers << "abstract" if node.is_abstract
|
724
|
-
|
724
|
+
|
725
|
+
if node.is_override
|
726
|
+
modifiers << if node.allow_incompatible_override
|
727
|
+
"override(allow_incompatible: true)"
|
728
|
+
else
|
729
|
+
"override"
|
730
|
+
end
|
731
|
+
end
|
732
|
+
|
725
733
|
modifiers << "overridable" if node.is_overridable
|
726
734
|
modifiers << "type_parameters(#{node.type_params.map { |type| ":#{type}" }.join(", ")})" if node.type_params.any?
|
727
735
|
modifiers << "checked(:#{node.checked})" if node.checked
|
data/lib/rbi/rbs_printer.rb
CHANGED
@@ -273,19 +273,24 @@ module RBI
|
|
273
273
|
|
274
274
|
sig { params(node: RBI::Attr, sig: Sig).void }
|
275
275
|
def print_attr_sig(node, sig)
|
276
|
+
ret_type = sig.return_type
|
277
|
+
|
276
278
|
type = case node
|
277
|
-
when
|
278
|
-
parse_type(
|
279
|
+
when AttrReader, AttrAccessor
|
280
|
+
parse_type(ret_type).rbs_string
|
279
281
|
else
|
280
|
-
|
281
|
-
|
282
|
-
|
282
|
+
# For attr_writer, Sorbet will prioritize the return type over the argument type in case of mismatch
|
283
|
+
arg_type = sig.params.first
|
284
|
+
if arg_type && (ret_type.is_a?(Type::Void) || ret_type == "void")
|
285
|
+
# If we have an argument type and the return type is void, we prioritize the argument type
|
286
|
+
parse_type(arg_type.type).rbs_string
|
283
287
|
else
|
284
|
-
|
288
|
+
# Otherwise, we prioritize the return type
|
289
|
+
parse_type(ret_type).rbs_string
|
285
290
|
end
|
286
291
|
end
|
287
292
|
|
288
|
-
print(type
|
293
|
+
print(type)
|
289
294
|
end
|
290
295
|
|
291
296
|
sig { override.params(node: Method).void }
|
@@ -298,13 +303,21 @@ module RBI
|
|
298
303
|
end
|
299
304
|
|
300
305
|
if node.sigs.any?(&:is_override)
|
301
|
-
|
306
|
+
if node.sigs.any?(&:allow_incompatible_override)
|
307
|
+
printl("# @override(allow_incompatible: true)")
|
308
|
+
else
|
309
|
+
printl("# @override")
|
310
|
+
end
|
302
311
|
end
|
303
312
|
|
304
313
|
if node.sigs.any?(&:is_overridable)
|
305
314
|
printl("# @overridable")
|
306
315
|
end
|
307
316
|
|
317
|
+
if node.sigs.any?(&:is_final)
|
318
|
+
printl("# @final")
|
319
|
+
end
|
320
|
+
|
308
321
|
print_loc(node)
|
309
322
|
printt
|
310
323
|
unless in_visibility_group || node.visibility.public?
|
@@ -349,7 +362,7 @@ module RBI
|
|
349
362
|
sig { params(node: RBI::Method, sig: Sig).void }
|
350
363
|
def print_method_sig(node, sig)
|
351
364
|
unless sig.type_params.empty?
|
352
|
-
print("[#{sig.type_params.
|
365
|
+
print("[#{sig.type_params.join(", ")}] ")
|
353
366
|
end
|
354
367
|
|
355
368
|
block_param = node.params.find { |param| param.is_a?(BlockParam) }
|
@@ -388,9 +401,7 @@ module RBI
|
|
388
401
|
type_string = "(?) -> untyped"
|
389
402
|
block_is_nilable = true
|
390
403
|
when Type::Simple
|
391
|
-
|
392
|
-
type_string = "(?) -> untyped"
|
393
|
-
end
|
404
|
+
type_string = "(?) -> untyped"
|
394
405
|
skip = true if block_type.name == "NilClass"
|
395
406
|
end
|
396
407
|
|
@@ -410,6 +421,24 @@ module RBI
|
|
410
421
|
print(" # #{loc}") if loc && print_locs
|
411
422
|
end
|
412
423
|
|
424
|
+
sig { params(node: Sig).void }
|
425
|
+
def visit_sig(node)
|
426
|
+
if node.params
|
427
|
+
print("(")
|
428
|
+
node.params.each do |param|
|
429
|
+
visit(param)
|
430
|
+
end
|
431
|
+
print(") ")
|
432
|
+
end
|
433
|
+
|
434
|
+
print("-> #{parse_type(node.return_type).rbs_string}")
|
435
|
+
end
|
436
|
+
|
437
|
+
sig { params(node: SigParam).void }
|
438
|
+
def visit_sig_param(node)
|
439
|
+
print(parse_type(node.type).rbs_string)
|
440
|
+
end
|
441
|
+
|
413
442
|
sig { override.params(node: ReqParam).void }
|
414
443
|
def visit_req_param(node)
|
415
444
|
print("untyped #{node.name}")
|
@@ -834,7 +863,7 @@ module RBI
|
|
834
863
|
|
835
864
|
sig { params(type: Type::Simple).void }
|
836
865
|
def visit_simple(type)
|
837
|
-
@string << translate_t_type(type.name)
|
866
|
+
@string << translate_t_type(type.name.gsub(/\s/, ""))
|
838
867
|
end
|
839
868
|
|
840
869
|
sig { params(type: Type::Boolean).void }
|
@@ -844,7 +873,7 @@ module RBI
|
|
844
873
|
|
845
874
|
sig { params(type: Type::Generic).void }
|
846
875
|
def visit_generic(type)
|
847
|
-
@string << translate_t_type(type.name)
|
876
|
+
@string << translate_t_type(type.name.gsub(/\s/, ""))
|
848
877
|
@string << "["
|
849
878
|
type.params.each_with_index do |arg, index|
|
850
879
|
visit(arg)
|
@@ -885,7 +914,14 @@ module RBI
|
|
885
914
|
|
886
915
|
sig { params(type: Type::Nilable).void }
|
887
916
|
def visit_nilable(type)
|
888
|
-
|
917
|
+
inner = type.type
|
918
|
+
if inner.is_a?(Type::Proc)
|
919
|
+
@string << "("
|
920
|
+
end
|
921
|
+
visit(inner)
|
922
|
+
if inner.is_a?(Type::Proc)
|
923
|
+
@string << ")"
|
924
|
+
end
|
889
925
|
@string << "?"
|
890
926
|
end
|
891
927
|
|
@@ -930,7 +966,16 @@ module RBI
|
|
930
966
|
def visit_shape(type)
|
931
967
|
@string << "{"
|
932
968
|
type.types.each_with_index do |(key, value), index|
|
933
|
-
@string <<
|
969
|
+
@string << case key
|
970
|
+
when String
|
971
|
+
"\"#{key}\" => "
|
972
|
+
when Symbol
|
973
|
+
if key.match?(/\A[a-zA-Z_]+[a-zA-Z0-9_]*\z/)
|
974
|
+
"#{key}: "
|
975
|
+
else
|
976
|
+
"\"#{key}\": "
|
977
|
+
end
|
978
|
+
end
|
934
979
|
visit(value)
|
935
980
|
@string << ", " if index < type.types.size - 1
|
936
981
|
end
|
@@ -949,20 +994,26 @@ module RBI
|
|
949
994
|
end
|
950
995
|
@string << ") "
|
951
996
|
end
|
997
|
+
proc_bind = type.proc_bind
|
998
|
+
if proc_bind
|
999
|
+
@string << "[self: "
|
1000
|
+
visit(proc_bind)
|
1001
|
+
@string << "] "
|
1002
|
+
end
|
952
1003
|
@string << "-> "
|
953
1004
|
visit(type.proc_returns)
|
954
1005
|
end
|
955
1006
|
|
956
1007
|
sig { params(type: Type::TypeParameter).void }
|
957
1008
|
def visit_type_parameter(type)
|
958
|
-
@string <<
|
1009
|
+
@string << type.name.to_s
|
959
1010
|
end
|
960
1011
|
|
961
1012
|
sig { params(type: Type::Class).void }
|
962
1013
|
def visit_class(type)
|
963
|
-
@string << "
|
1014
|
+
@string << "Class["
|
964
1015
|
visit(type.type)
|
965
|
-
@string << "
|
1016
|
+
@string << "]"
|
966
1017
|
end
|
967
1018
|
|
968
1019
|
private
|
data/lib/rbi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Terrasa
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-21 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: prism
|
@@ -38,7 +37,6 @@ dependencies:
|
|
38
37
|
- - ">="
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: 0.5.9204
|
41
|
-
description:
|
42
40
|
email:
|
43
41
|
- ruby@shopify.com
|
44
42
|
executables: []
|
@@ -80,7 +78,6 @@ licenses:
|
|
80
78
|
- MIT
|
81
79
|
metadata:
|
82
80
|
allowed_push_host: https://rubygems.org
|
83
|
-
post_install_message:
|
84
81
|
rdoc_options: []
|
85
82
|
require_paths:
|
86
83
|
- lib
|
@@ -95,8 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
92
|
- !ruby/object:Gem::Version
|
96
93
|
version: '0'
|
97
94
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
99
|
-
signing_key:
|
95
|
+
rubygems_version: 3.6.2
|
100
96
|
specification_version: 4
|
101
97
|
summary: RBI generation framework
|
102
98
|
test_files: []
|