rbi 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbi/formatter.rb +0 -3
- data/lib/rbi/model.rb +4 -1
- data/lib/rbi/parser.rb +16 -0
- 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: 7d7b27863b9b9ece5a4cc59fb638a2e51055cd2ca39416e311ea38e9929f124e
|
4
|
+
data.tar.gz: 24356f96be5c3381865496aab481214a0cfcbfa423b29eb728691b973a051a5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd47ce37c3cd31e92d24172e08bb9c1a6a0416a3399bb39529788655f0b1138947cd35a9afb85cc0915c2e04989cdd9f1a04b8a2a511dfd64a1ca6ee82701edc
|
7
|
+
data.tar.gz: eddda9af791aef98efb957b0017376cdc058a96aff0b39c6716ee5e18809da21b12d4a5b79df1c34c923a0c34383286785de5e160934aff3a93289f756a6dac5
|
data/lib/rbi/formatter.rb
CHANGED
data/lib/rbi/model.rb
CHANGED
@@ -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)
|
data/lib/rbi/parser.rb
CHANGED
@@ -858,6 +858,22 @@ module RBI
|
|
858
858
|
end
|
859
859
|
when "override"
|
860
860
|
@current.is_override = true
|
861
|
+
|
862
|
+
args = node.arguments&.arguments
|
863
|
+
|
864
|
+
keywords_hash = args
|
865
|
+
&.grep(Prism::KeywordHashNode)
|
866
|
+
&.first
|
867
|
+
|
868
|
+
allow_incompatible_override = keywords_hash
|
869
|
+
&.elements
|
870
|
+
&.any? do |assoc|
|
871
|
+
assoc.is_a?(Prism::AssocNode) &&
|
872
|
+
node_string(assoc.key) == "allow_incompatible:" &&
|
873
|
+
node_string(assoc.value) == "true"
|
874
|
+
end
|
875
|
+
|
876
|
+
@current.allow_incompatible_override = !!allow_incompatible_override
|
861
877
|
when "overridable"
|
862
878
|
@current.is_overridable = true
|
863
879
|
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.3
|
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-15 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: []
|