rbi 0.3.6 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80df141e229452edf3fb51dc8933c130ce2a2f972ee6906be79680d79f33a720
4
- data.tar.gz: '099a5b5fb43ccd50cf262bcdbc0d8fde6cd0aa14983851c9de14f488def2a56b'
3
+ metadata.gz: d0977bf3c0892a76c8d66ec2f295a62948530bcd2eee11911c50e36ac1bf5402
4
+ data.tar.gz: ae51e44eb13fe8045f200a8a0353daa9969c4389f99c73758713fa0a9b2b9b0f
5
5
  SHA512:
6
- metadata.gz: 791d993759d3e237a52d34be622c23eec92d1adb26b267aa47b3aa9e7ce1767b96fff75e02d895493fb63b84fe3f15cb1c37f880db1698e5a8b9e17cba77503e
7
- data.tar.gz: cdf11ef801d7ac8a1329b39e095c4895d006ae46ad800d50d1d2cb52aa9c41fdb704557a8a660376b53e4bdb86a076bacde0a5a2c33d0031478dda36850297b1
6
+ metadata.gz: 32bafbbfffee840fe60a1633eb8b408aca4c8e39b5359ce3deca5185ab3003ac43b6c6cab4c4639d9e87e12afabcf1ee042bc9b5a56a231302354f884b2c27ea
7
+ data.tar.gz: da025803fafaf40714356d02dfe77a705a0de38050bdce9616c6e35f68479b958aa0eb5b596ddf146ef1493932a70fead22f7cb745a28e7c15a40ee85a850c2e
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.3")
13
- gem("rubocop", "~> 1.76", require: false)
13
+ gem("rubocop", "~> 1.81", 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
@@ -6,7 +6,15 @@ module RBI
6
6
  #: Integer?
7
7
  attr_accessor :max_line_length
8
8
 
9
- #: (?add_sig_templates: bool, ?group_nodes: bool, ?max_line_length: Integer?, ?nest_singleton_methods: bool, ?nest_non_public_members: bool, ?sort_nodes: bool, ?replace_attributes_with_methods: bool) -> void
9
+ #: (
10
+ #| ?add_sig_templates: bool,
11
+ #| ?group_nodes: bool,
12
+ #| ?max_line_length: Integer?,
13
+ #| ?nest_singleton_methods: bool,
14
+ #| ?nest_non_public_members: bool,
15
+ #| ?sort_nodes: bool,
16
+ #| ?replace_attributes_with_methods: bool
17
+ #| ) -> void
10
18
  def initialize(
11
19
  add_sig_templates: false,
12
20
  group_nodes: false,
data/lib/rbi/index.rb CHANGED
@@ -73,7 +73,7 @@ module RBI
73
73
  # getter and the setter.
74
74
  # @abstract
75
75
  #: -> Array[String]
76
- def index_ids; end
76
+ def index_ids = raise NotImplementedError, "Abstract method called"
77
77
  end
78
78
 
79
79
  class Scope
data/lib/rbi/loc.rb CHANGED
@@ -22,7 +22,13 @@ module RBI
22
22
  #: Integer?
23
23
  attr_reader :begin_line, :end_line, :begin_column, :end_column
24
24
 
25
- #: (?file: String?, ?begin_line: Integer?, ?end_line: Integer?, ?begin_column: Integer?, ?end_column: Integer?) -> void
25
+ #: (
26
+ #| ?file: String?,
27
+ #| ?begin_line: Integer?,
28
+ #| ?end_line: Integer?,
29
+ #| ?begin_column: Integer?,
30
+ #| ?end_column: Integer?
31
+ #| ) -> void
26
32
  def initialize(file: nil, begin_line: nil, end_line: nil, begin_column: nil, end_column: nil)
27
33
  @file = file
28
34
  @begin_line = begin_line
data/lib/rbi/model.rb CHANGED
@@ -163,7 +163,7 @@ module RBI
163
163
  class Scope < Tree
164
164
  # @abstract
165
165
  #: -> String
166
- def fully_qualified_name; end
166
+ def fully_qualified_name = raise NotImplementedError, "Abstract method called"
167
167
 
168
168
  # @override
169
169
  #: -> String
@@ -240,7 +240,13 @@ module RBI
240
240
  #: bool
241
241
  attr_accessor :keyword_init
242
242
 
243
- #: (String name, ?members: Array[Symbol], ?keyword_init: bool, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Struct struct) -> void } -> void
243
+ #: (
244
+ #| String name,
245
+ #| ?members: Array[Symbol],
246
+ #| ?keyword_init: bool,
247
+ #| ?loc: Loc?,
248
+ #| ?comments: Array[Comment]
249
+ #| ) ?{ (Struct struct) -> void } -> void
244
250
  def initialize(name, members: [], keyword_init: false, loc: nil, comments: [], &block)
245
251
  super(loc: loc, comments: comments) {}
246
252
  @name = name
@@ -299,7 +305,14 @@ module RBI
299
305
  #: Array[Sig]
300
306
  attr_reader :sigs
301
307
 
302
- #: (Symbol name, Array[Symbol] names, ?visibility: Visibility, ?sigs: Array[Sig], ?loc: Loc?, ?comments: Array[Comment]) -> void
308
+ #: (
309
+ #| Symbol name,
310
+ #| Array[Symbol] names,
311
+ #| ?visibility: Visibility,
312
+ #| ?sigs: Array[Sig],
313
+ #| ?loc: Loc?,
314
+ #| ?comments: Array[Comment]
315
+ #| ) -> void
303
316
  def initialize(name, names, visibility: Public.new, sigs: [], loc: nil, comments: [])
304
317
  super(loc: loc, comments: comments)
305
318
  @names = [name, *names] #: Array[Symbol]
@@ -309,11 +322,18 @@ module RBI
309
322
 
310
323
  # @abstract
311
324
  #: -> Array[String]
312
- def fully_qualified_names; end
325
+ def fully_qualified_names = raise NotImplementedError, "Abstract method called"
313
326
  end
314
327
 
315
328
  class AttrAccessor < Attr
316
- #: (Symbol name, *Symbol names, ?visibility: Visibility, ?sigs: Array[Sig], ?loc: Loc?, ?comments: Array[Comment]) ?{ (AttrAccessor node) -> void } -> void
329
+ #: (
330
+ #| Symbol name,
331
+ #| *Symbol names,
332
+ #| ?visibility: Visibility,
333
+ #| ?sigs: Array[Sig],
334
+ #| ?loc: Loc?,
335
+ #| ?comments: Array[Comment]
336
+ #| ) ?{ (AttrAccessor node) -> void } -> void
317
337
  def initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block)
318
338
  super(name, names, loc: loc, visibility: visibility, sigs: sigs, comments: comments)
319
339
  block&.call(self)
@@ -335,7 +355,14 @@ module RBI
335
355
  end
336
356
 
337
357
  class AttrReader < Attr
338
- #: (Symbol name, *Symbol names, ?visibility: Visibility, ?sigs: Array[Sig], ?loc: Loc?, ?comments: Array[Comment]) ?{ (AttrReader node) -> void } -> void
358
+ #: (
359
+ #| Symbol name,
360
+ #| *Symbol names,
361
+ #| ?visibility: Visibility,
362
+ #| ?sigs: Array[Sig],
363
+ #| ?loc: Loc?,
364
+ #| ?comments: Array[Comment]
365
+ #| ) ?{ (AttrReader node) -> void } -> void
339
366
  def initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block)
340
367
  super(name, names, loc: loc, visibility: visibility, sigs: sigs, comments: comments)
341
368
  block&.call(self)
@@ -357,7 +384,14 @@ module RBI
357
384
  end
358
385
 
359
386
  class AttrWriter < Attr
360
- #: (Symbol name, *Symbol names, ?visibility: Visibility, ?sigs: Array[Sig], ?loc: Loc?, ?comments: Array[Comment]) ?{ (AttrWriter node) -> void } -> void
387
+ #: (
388
+ #| Symbol name,
389
+ #| *Symbol names,
390
+ #| ?visibility: Visibility,
391
+ #| ?sigs: Array[Sig],
392
+ #| ?loc: Loc?,
393
+ #| ?comments: Array[Comment]
394
+ #| ) ?{ (AttrWriter node) -> void } -> void
361
395
  def initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block)
362
396
  super(name, names, loc: loc, visibility: visibility, sigs: sigs, comments: comments)
363
397
  block&.call(self)
@@ -396,7 +430,15 @@ module RBI
396
430
  #: Array[Sig]
397
431
  attr_accessor :sigs
398
432
 
399
- #: (String name, ?params: Array[Param], ?is_singleton: bool, ?visibility: Visibility, ?sigs: Array[Sig], ?loc: Loc?, ?comments: Array[Comment]) ?{ (Method node) -> void } -> void
433
+ #: (
434
+ #| String name,
435
+ #| ?params: Array[Param],
436
+ #| ?is_singleton: bool,
437
+ #| ?visibility: Visibility,
438
+ #| ?sigs: Array[Sig],
439
+ #| ?loc: Loc?,
440
+ #| ?comments: Array[Comment]
441
+ #| ) ?{ (Method node) -> void } -> void
400
442
  def initialize(
401
443
  name,
402
444
  params: [],
@@ -456,7 +498,15 @@ module RBI
456
498
  @params << BlockParam.new(name)
457
499
  end
458
500
 
459
- #: (?params: Array[SigParam], ?return_type: (String | Type), ?is_abstract: bool, ?is_override: bool, ?is_overridable: bool, ?is_final: bool, ?type_params: Array[String], ?checked: Symbol?) ?{ (Sig node) -> void } -> void
501
+ #: (
502
+ #| ?params: Array[SigParam],
503
+ #| ?return_type: (String | Type),
504
+ #| ?is_abstract: bool,
505
+ #| ?is_override: bool,
506
+ #| ?is_overridable: bool,
507
+ #| ?is_final: bool,
508
+ #| ?type_params: Array[String],
509
+ #| ?checked: Symbol?) ?{ (Sig node) -> void } -> void
460
510
  def add_sig(
461
511
  params: [],
462
512
  return_type: "void",
@@ -832,7 +882,25 @@ module RBI
832
882
  attr_accessor :return_type
833
883
 
834
884
  #: bool
835
- attr_accessor :is_abstract, :is_override, :is_overridable, :is_final, :allow_incompatible_override, :without_runtime
885
+ attr_accessor :is_abstract
886
+
887
+ #: bool
888
+ attr_accessor :is_override
889
+
890
+ #: bool
891
+ attr_accessor :is_overridable
892
+
893
+ #: bool
894
+ attr_accessor :is_final
895
+
896
+ #: bool
897
+ attr_accessor :allow_incompatible_override
898
+
899
+ #: bool
900
+ attr_accessor :allow_incompatible_override_visibility
901
+
902
+ #: bool
903
+ attr_accessor :without_runtime
836
904
 
837
905
  #: Array[String]
838
906
  attr_reader :type_params
@@ -840,7 +908,21 @@ module RBI
840
908
  #: Symbol?
841
909
  attr_accessor :checked
842
910
 
843
- #: (?params: Array[SigParam], ?return_type: (Type | String), ?is_abstract: bool, ?is_override: bool, ?is_overridable: bool, ?is_final: bool, ?allow_incompatible_override: bool, ?without_runtime: bool, ?type_params: Array[String], ?checked: Symbol?, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Sig node) -> void } -> void
911
+ #: (
912
+ #| ?params: Array[SigParam],
913
+ #| ?return_type: (Type | String),
914
+ #| ?is_abstract: bool,
915
+ #| ?is_override: bool,
916
+ #| ?is_overridable: bool,
917
+ #| ?is_final: bool,
918
+ #| ?allow_incompatible_override: bool,
919
+ #| ?allow_incompatible_override_visibility: bool,
920
+ #| ?without_runtime: bool,
921
+ #| ?type_params: Array[String],
922
+ #| ?checked: Symbol?,
923
+ #| ?loc: Loc?,
924
+ #| ?comments: Array[Comment]
925
+ #| ) ?{ (Sig node) -> void } -> void
844
926
  def initialize(
845
927
  params: [],
846
928
  return_type: "void",
@@ -849,6 +931,7 @@ module RBI
849
931
  is_overridable: false,
850
932
  is_final: false,
851
933
  allow_incompatible_override: false,
934
+ allow_incompatible_override_visibility: false,
852
935
  without_runtime: false,
853
936
  type_params: [],
854
937
  checked: nil,
@@ -864,6 +947,7 @@ module RBI
864
947
  @is_overridable = is_overridable
865
948
  @is_final = is_final
866
949
  @allow_incompatible_override = allow_incompatible_override
950
+ @allow_incompatible_override_visibility = allow_incompatible_override_visibility
867
951
  @without_runtime = without_runtime
868
952
  @type_params = type_params
869
953
  @checked = checked
@@ -942,11 +1026,17 @@ module RBI
942
1026
 
943
1027
  # @abstract
944
1028
  #: -> Array[String]
945
- def fully_qualified_names; end
1029
+ def fully_qualified_names = raise NotImplementedError, "Abstract method called"
946
1030
  end
947
1031
 
948
1032
  class TStructConst < TStructField
949
- #: (String name, (Type | String) type, ?default: String?, ?loc: Loc?, ?comments: Array[Comment]) ?{ (TStructConst node) -> void } -> void
1033
+ #: (
1034
+ #| String name,
1035
+ #| (Type | String) type,
1036
+ #| ?default: String?,
1037
+ #| ?loc: Loc?,
1038
+ #| ?comments: Array[Comment]
1039
+ #| ) ?{ (TStructConst node) -> void } -> void
950
1040
  def initialize(name, type, default: nil, loc: nil, comments: [], &block)
951
1041
  super(name, type, default: default, loc: loc, comments: comments)
952
1042
  block&.call(self)
@@ -967,7 +1057,13 @@ module RBI
967
1057
  end
968
1058
 
969
1059
  class TStructProp < TStructField
970
- #: (String name, (Type | String) type, ?default: String?, ?loc: Loc?, ?comments: Array[Comment]) ?{ (TStructProp node) -> void } -> void
1060
+ #: (
1061
+ #| String name,
1062
+ #| (Type | String) type,
1063
+ #| ?default: String?,
1064
+ #| ?loc: Loc?,
1065
+ #| ?comments: Array[Comment]
1066
+ #| ) ?{ (TStructProp node) -> void } -> void
971
1067
  def initialize(name, type, default: nil, loc: nil, comments: [], &block)
972
1068
  super(name, type, default: default, loc: loc, comments: comments)
973
1069
  block&.call(self)
@@ -1087,7 +1183,12 @@ module RBI
1087
1183
  end
1088
1184
 
1089
1185
  class MixesInClassMethods < Mixin
1090
- #: (String name, *String names, ?loc: Loc?, ?comments: Array[Comment]) ?{ (MixesInClassMethods node) -> void } -> void
1186
+ #: (
1187
+ #| String name,
1188
+ #| *String names,
1189
+ #| ?loc: Loc?,
1190
+ #| ?comments: Array[Comment]
1191
+ #| ) ?{ (MixesInClassMethods node) -> void } -> void
1091
1192
  def initialize(name, *names, loc: nil, comments: [], &block)
1092
1193
  super(name, names, loc: loc, comments: comments)
1093
1194
  block&.call(self)
data/lib/rbi/parser.rb CHANGED
@@ -946,22 +946,8 @@ module RBI
946
946
  end
947
947
  when "override"
948
948
  @current.is_override = true
949
-
950
- args = node.arguments&.arguments
951
-
952
- keywords_hash = args
953
- &.grep(Prism::KeywordHashNode)
954
- &.first
955
-
956
- allow_incompatible_override = keywords_hash
957
- &.elements
958
- &.any? do |assoc|
959
- assoc.is_a?(Prism::AssocNode) &&
960
- node_string(assoc.key) == "allow_incompatible:" &&
961
- node_string(assoc.value) == "true"
962
- end
963
-
964
- @current.allow_incompatible_override = !!allow_incompatible_override
949
+ @current.allow_incompatible_override = allow_incompatible_override?(node, "true")
950
+ @current.allow_incompatible_override_visibility = allow_incompatible_override?(node, ":visibility")
965
951
  when "overridable"
966
952
  @current.is_overridable = true
967
953
  when "params"
@@ -995,6 +981,23 @@ module RBI
995
981
  node_string!(node.value),
996
982
  )
997
983
  end
984
+
985
+ #: (Prism::CallNode node, String value) -> bool
986
+ def allow_incompatible_override?(node, value)
987
+ args = node.arguments&.arguments
988
+
989
+ keywords_hash = args
990
+ &.grep(Prism::KeywordHashNode)
991
+ &.first
992
+
993
+ !!keywords_hash
994
+ &.elements
995
+ &.any? do |assoc|
996
+ assoc.is_a?(Prism::AssocNode) &&
997
+ node_string(assoc.key) == "allow_incompatible:" &&
998
+ node_string(assoc.value) == value
999
+ end
1000
+ end
998
1001
  end
999
1002
 
1000
1003
  class HeredocLocationVisitor < Prism::Visitor
data/lib/rbi/printer.rb CHANGED
@@ -800,6 +800,8 @@ module RBI
800
800
  if node.is_override
801
801
  modifiers << if node.allow_incompatible_override
802
802
  "override(allow_incompatible: true)"
803
+ elsif node.allow_incompatible_override_visibility
804
+ "override(allow_incompatible: :visibility)"
803
805
  else
804
806
  "override"
805
807
  end
@@ -34,7 +34,7 @@ module RBI
34
34
  case type
35
35
  when ::RBS::Types::Alias
36
36
  # TODO: unsupported yet
37
- Type.untyped
37
+ translate_type_alias(type)
38
38
  when ::RBS::Types::Bases::Any
39
39
  Type.untyped
40
40
  when ::RBS::Types::Bases::Bool
@@ -85,12 +85,24 @@ module RBI
85
85
  when ::RBS::Types::Variable
86
86
  Type.type_parameter(type.name)
87
87
  else
88
- T.absurd(type)
88
+ type #: absurd
89
89
  end
90
90
  end
91
91
 
92
92
  private
93
93
 
94
+ #: (::RBS::Types::Alias) -> Type
95
+ def translate_type_alias(type)
96
+ name = ::RBS::TypeName.new(
97
+ namespace: type.name.namespace,
98
+ name: type.name.name.to_s.gsub(/(?:^|_)([a-z\d]*)/i) do |match|
99
+ match = match.delete_prefix("_")
100
+ !match.empty? ? match[0].upcase.concat(match[1..-1]) : +""
101
+ end,
102
+ )
103
+ Type.simple(name.to_s)
104
+ end
105
+
94
106
  #: (::RBS::Types::ClassInstance) -> Type
95
107
  def translate_class_instance(type)
96
108
  return Type.simple(type.name.to_s) if type.args.empty?
@@ -337,6 +337,8 @@ module RBI
337
337
  if node.sigs.any?(&:is_override)
338
338
  if node.sigs.any?(&:allow_incompatible_override)
339
339
  printl("# @override(allow_incompatible: true)")
340
+ elsif node.sigs.any?(&:allow_incompatible_override_visibility)
341
+ printl("# @override(allow_incompatible: :visibility)")
340
342
  else
341
343
  printl("# @override")
342
344
  end
@@ -56,7 +56,7 @@ module RBI
56
56
  class Attr
57
57
  # @abstract
58
58
  #: -> Array[Method]
59
- def convert_to_methods; end
59
+ def convert_to_methods = raise NotImplementedError, "Abstract method called"
60
60
 
61
61
  private
62
62
 
@@ -88,7 +88,14 @@ module RBI
88
88
  )
89
89
  end
90
90
 
91
- #: (String name, Sig? sig, (Type | String)? attribute_type, Visibility visibility, Loc? loc, Array[Comment] comments) -> Method
91
+ #: (
92
+ #| String name,
93
+ #| Sig? sig,
94
+ #| (Type | String)? attribute_type,
95
+ #| Visibility visibility,
96
+ #| Loc? loc,
97
+ #| Array[Comment] comments
98
+ #| ) -> Method
92
99
  def create_setter_method(name, sig, attribute_type, visibility, loc, comments) # rubocop:disable Metrics/ParameterLists
93
100
  sig = if sig # Modify the original sig to correct the name, and remove the return type
94
101
  params = attribute_type ? [SigParam.new(name, attribute_type)] : []
@@ -330,7 +330,11 @@ module RBI
330
330
  #: Array[Rewriters::Merge::Conflict]
331
331
  attr_reader :conflicts
332
332
 
333
- #: (?loc: Loc?, ?comments: Array[Comment], ?conflicts: Array[Rewriters::Merge::Conflict]) ?{ (Tree node) -> void } -> void
333
+ #: (
334
+ #| ?loc: Loc?,
335
+ #| ?comments: Array[Comment],
336
+ #| ?conflicts: Array[Rewriters::Merge::Conflict]
337
+ #| ) ?{ (Tree node) -> void } -> void
334
338
  def initialize(loc: nil, comments: [], conflicts: [], &block)
335
339
  super(loc: loc, comments: comments)
336
340
  @conflicts = conflicts
data/lib/rbi/type.rb CHANGED
@@ -583,6 +583,46 @@ module RBI
583
583
  end
584
584
  end
585
585
 
586
+ # A type alias that references another type by name like `MyTypeAlias`.
587
+ class TypeAlias < Type
588
+ #: String
589
+ attr_reader :name
590
+
591
+ #: Type
592
+ attr_reader :aliased_type
593
+
594
+ #: (String name, Type aliased_type) -> void
595
+ def initialize(name, aliased_type)
596
+ super()
597
+ @name = name
598
+ @aliased_type = aliased_type
599
+ end
600
+
601
+ # @override
602
+ #: (BasicObject other) -> bool
603
+ def ==(other)
604
+ TypeAlias === other && @name == other.name && @aliased_type == other.aliased_type
605
+ end
606
+
607
+ # @override
608
+ #: -> String
609
+ def to_rbi
610
+ "#{name} = T.type_alias { #{aliased_type.to_rbi} }"
611
+ end
612
+
613
+ # @override
614
+ #: -> Type
615
+ def normalize
616
+ TypeAlias.new(name, aliased_type.normalize)
617
+ end
618
+
619
+ # @override
620
+ #: -> Type
621
+ def simplify
622
+ TypeAlias.new(name, aliased_type.simplify)
623
+ end
624
+ end
625
+
586
626
  # Tuples and shapes
587
627
 
588
628
  # A tuple type like `[String, Integer]`.
@@ -871,6 +911,12 @@ module RBI
871
911
  TypeParameter.new(name)
872
912
  end
873
913
 
914
+ # Builds a type that represents a type alias like `MyTypeAlias`.
915
+ #: (String name, Type aliased_type) -> TypeAlias
916
+ def type_alias(name, aliased_type)
917
+ TypeAlias.new(name, aliased_type)
918
+ end
919
+
874
920
  # Tuples and shapes
875
921
 
876
922
  # Builds a type that represents a tuple type like `[String, Integer]`.
@@ -957,7 +1003,7 @@ module RBI
957
1003
  #
958
1004
  # @abstract
959
1005
  #: -> Type
960
- def normalize; end
1006
+ def normalize = raise NotImplementedError, "Abstract method called"
961
1007
 
962
1008
  # Returns a simplified version of the type.
963
1009
  #
@@ -969,11 +1015,11 @@ module RBI
969
1015
  #
970
1016
  # @abstract
971
1017
  #: -> Type
972
- def simplify; end
1018
+ def simplify = raise NotImplementedError, "Abstract method called"
973
1019
 
974
1020
  # @abstract
975
1021
  #: (BasicObject) -> bool
976
- def ==(other); end
1022
+ def ==(other) = raise NotImplementedError, "Abstract method called"
977
1023
 
978
1024
  #: (BasicObject other) -> bool
979
1025
  def eql?(other)
@@ -988,7 +1034,7 @@ module RBI
988
1034
 
989
1035
  # @abstract
990
1036
  #: -> String
991
- def to_rbi; end
1037
+ def to_rbi = raise NotImplementedError, "Abstract method called"
992
1038
 
993
1039
  # @override
994
1040
  #: -> String
@@ -27,6 +27,8 @@ module RBI
27
27
  case node
28
28
  when Prism::ConstantReadNode, Prism::ConstantPathNode
29
29
  parse_constant(node)
30
+ when Prism::ConstantWriteNode, Prism::ConstantPathWriteNode
31
+ parse_constant_assignment(node)
30
32
  when Prism::CallNode
31
33
  parse_call(node)
32
34
  when Prism::ArrayNode
@@ -67,6 +69,29 @@ module RBI
67
69
  end
68
70
  end
69
71
 
72
+ #: (Prism::ConstantWriteNode | Prism::ConstantPathWriteNode node) -> Type
73
+ def parse_constant_assignment(node)
74
+ if t_type_alias?(node.value)
75
+ value = node.value #: as Prism::CallNode
76
+ name = if node.is_a?(Prism::ConstantPathWriteNode)
77
+ node.target.full_name
78
+ else
79
+ node.full_name
80
+ end
81
+
82
+ body = value.block
83
+
84
+ if body.is_a?(Prism::BlockNode) && (stmts = body.body).is_a?(Prism::StatementsNode)
85
+ body_node = stmts.body.first #: as !nil
86
+ Type::TypeAlias.new(name, parse_node(body_node))
87
+ else
88
+ Type::Simple.new(node.slice)
89
+ end
90
+ else
91
+ Type::Simple.new(node.slice)
92
+ end
93
+ end
94
+
70
95
  #: (Prism::CallNode node) -> Type
71
96
  def parse_call(node)
72
97
  recv = node.receiver
@@ -310,6 +335,13 @@ module RBI
310
335
  false
311
336
  end
312
337
 
338
+ #: (Prism::Node? node) -> bool
339
+ def t_type_alias?(node)
340
+ return false unless node.is_a?(Prism::CallNode)
341
+
342
+ t?(node.receiver) && node.name == :type_alias
343
+ end
344
+
313
345
  #: (Prism::Node? node) -> bool
314
346
  def t_boolean?(node)
315
347
  return false unless node.is_a?(Prism::ConstantPathNode)
@@ -45,6 +45,8 @@ module RBI
45
45
  visit_type_parameter(node)
46
46
  when Type::Class
47
47
  visit_class(node)
48
+ when Type::TypeAlias
49
+ visit_type_alias(node)
48
50
  else
49
51
  raise Error, "Unhandled node: #{node.class}"
50
52
  end
@@ -105,6 +107,9 @@ module RBI
105
107
 
106
108
  #: (Type::Untyped type) -> void
107
109
  def visit_untyped(type); end
110
+
111
+ #: (Type::TypeAlias type) -> void
112
+ def visit_type_alias(type); end
108
113
  end
109
114
  end
110
115
  end
data/lib/rbi/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module RBI
5
- VERSION = "0.3.6"
5
+ VERSION = "0.3.7"
6
6
  end
data/rbi/rbi.rbi CHANGED
@@ -968,6 +968,9 @@ class RBI::Parser::SigBuilder < ::RBI::Parser::Visitor
968
968
  sig { params(content: ::String, file: ::String).void }
969
969
  def initialize(content, file:); end
970
970
 
971
+ sig { params(node: ::Prism::CallNode, value: ::String).returns(T::Boolean) }
972
+ def allow_incompatible_override?(node, value); end
973
+
971
974
  sig { returns(::RBI::Sig) }
972
975
  def current; end
973
976
 
@@ -1418,6 +1421,9 @@ class RBI::RBS::TypeTranslator
1418
1421
 
1419
1422
  sig { params(type_name: ::String).returns(::String) }
1420
1423
  def translate_t_generic_type(type_name); end
1424
+
1425
+ sig { params(type: ::RBS::Types::Alias).returns(::RBI::Type) }
1426
+ def translate_type_alias(type); end
1421
1427
  end
1422
1428
  end
1423
1429
 
@@ -2102,6 +2108,7 @@ class RBI::Sig < ::RBI::NodeWithComments
2102
2108
  is_overridable: T::Boolean,
2103
2109
  is_final: T::Boolean,
2104
2110
  allow_incompatible_override: T::Boolean,
2111
+ allow_incompatible_override_visibility: T::Boolean,
2105
2112
  without_runtime: T::Boolean,
2106
2113
  type_params: T::Array[::String],
2107
2114
  checked: T.nilable(::Symbol),
@@ -2110,7 +2117,7 @@ class RBI::Sig < ::RBI::NodeWithComments
2110
2117
  block: T.nilable(T.proc.params(node: ::RBI::Sig).void)
2111
2118
  ).void
2112
2119
  end
2113
- def initialize(params: T.unsafe(nil), return_type: T.unsafe(nil), is_abstract: T.unsafe(nil), is_override: T.unsafe(nil), is_overridable: T.unsafe(nil), is_final: T.unsafe(nil), allow_incompatible_override: T.unsafe(nil), without_runtime: T.unsafe(nil), type_params: T.unsafe(nil), checked: T.unsafe(nil), loc: T.unsafe(nil), comments: T.unsafe(nil), &block); end
2120
+ def initialize(params: T.unsafe(nil), return_type: T.unsafe(nil), is_abstract: T.unsafe(nil), is_override: T.unsafe(nil), is_overridable: T.unsafe(nil), is_final: T.unsafe(nil), allow_incompatible_override: T.unsafe(nil), allow_incompatible_override_visibility: T.unsafe(nil), without_runtime: T.unsafe(nil), type_params: T.unsafe(nil), checked: T.unsafe(nil), loc: T.unsafe(nil), comments: T.unsafe(nil), &block); end
2114
2121
 
2115
2122
  sig { params(param: ::RBI::SigParam).void }
2116
2123
  def <<(param); end
@@ -2121,9 +2128,16 @@ class RBI::Sig < ::RBI::NodeWithComments
2121
2128
  sig { params(name: ::String, type: T.any(::RBI::Type, ::String)).void }
2122
2129
  def add_param(name, type); end
2123
2130
 
2131
+ sig { returns(T::Boolean) }
2124
2132
  def allow_incompatible_override; end
2133
+
2125
2134
  def allow_incompatible_override=(_arg0); end
2126
2135
 
2136
+ sig { returns(T::Boolean) }
2137
+ def allow_incompatible_override_visibility; end
2138
+
2139
+ def allow_incompatible_override_visibility=(_arg0); end
2140
+
2127
2141
  sig { returns(T.nilable(::Symbol)) }
2128
2142
  def checked; end
2129
2143
 
@@ -2133,11 +2147,20 @@ class RBI::Sig < ::RBI::NodeWithComments
2133
2147
  def is_abstract; end
2134
2148
 
2135
2149
  def is_abstract=(_arg0); end
2150
+
2151
+ sig { returns(T::Boolean) }
2136
2152
  def is_final; end
2153
+
2137
2154
  def is_final=(_arg0); end
2155
+
2156
+ sig { returns(T::Boolean) }
2138
2157
  def is_overridable; end
2158
+
2139
2159
  def is_overridable=(_arg0); end
2160
+
2161
+ sig { returns(T::Boolean) }
2140
2162
  def is_override; end
2163
+
2141
2164
  def is_override=(_arg0); end
2142
2165
 
2143
2166
  sig { returns(T::Array[::RBI::SigParam]) }
@@ -2151,7 +2174,9 @@ class RBI::Sig < ::RBI::NodeWithComments
2151
2174
  sig { returns(T::Array[::String]) }
2152
2175
  def type_params; end
2153
2176
 
2177
+ sig { returns(T::Boolean) }
2154
2178
  def without_runtime; end
2179
+
2155
2180
  def without_runtime=(_arg0); end
2156
2181
  end
2157
2182
 
@@ -2611,6 +2636,9 @@ class RBI::Type
2611
2636
  sig { params(types: T.any(::RBI::Type, T::Array[::RBI::Type])).returns(::RBI::Type::Tuple) }
2612
2637
  def tuple(*types); end
2613
2638
 
2639
+ sig { params(name: ::String, aliased_type: ::RBI::Type).returns(::RBI::Type::TypeAlias) }
2640
+ def type_alias(name, aliased_type); end
2641
+
2614
2642
  sig { params(name: ::Symbol).returns(::RBI::Type::TypeParameter) }
2615
2643
  def type_parameter(name); end
2616
2644
 
@@ -2637,6 +2665,9 @@ class RBI::Type
2637
2665
  sig { params(node: T.any(::Prism::ConstantPathNode, ::Prism::ConstantReadNode)).returns(::RBI::Type) }
2638
2666
  def parse_constant(node); end
2639
2667
 
2668
+ sig { params(node: T.any(::Prism::ConstantPathWriteNode, ::Prism::ConstantWriteNode)).returns(::RBI::Type) }
2669
+ def parse_constant_assignment(node); end
2670
+
2640
2671
  sig { params(node: ::Prism::CallNode).returns(::RBI::Type) }
2641
2672
  def parse_proc(node); end
2642
2673
 
@@ -2661,6 +2692,9 @@ class RBI::Type
2661
2692
  sig { params(node: ::Prism::CallNode).returns(T::Boolean) }
2662
2693
  def t_proc?(node); end
2663
2694
 
2695
+ sig { params(node: T.nilable(::Prism::Node)).returns(T::Boolean) }
2696
+ def t_type_alias?(node); end
2697
+
2664
2698
  sig { params(name: ::String).returns(T::Boolean) }
2665
2699
  def valid_identifier?(name); end
2666
2700
  end
@@ -2960,6 +2994,29 @@ class RBI::Type::Tuple < ::RBI::Type
2960
2994
  def types; end
2961
2995
  end
2962
2996
 
2997
+ class RBI::Type::TypeAlias < ::RBI::Type
2998
+ sig { params(name: ::String, aliased_type: ::RBI::Type).void }
2999
+ def initialize(name, aliased_type); end
3000
+
3001
+ sig { override.params(other: ::BasicObject).returns(T::Boolean) }
3002
+ def ==(other); end
3003
+
3004
+ sig { returns(::RBI::Type) }
3005
+ def aliased_type; end
3006
+
3007
+ sig { returns(::String) }
3008
+ def name; end
3009
+
3010
+ sig { override.returns(::RBI::Type) }
3011
+ def normalize; end
3012
+
3013
+ sig { override.returns(::RBI::Type) }
3014
+ def simplify; end
3015
+
3016
+ sig { override.returns(::String) }
3017
+ def to_rbi; end
3018
+ end
3019
+
2963
3020
  class RBI::Type::TypeParameter < ::RBI::Type
2964
3021
  sig { params(name: ::Symbol).void }
2965
3022
  def initialize(name); end
@@ -3045,6 +3102,9 @@ class RBI::Type::Visitor
3045
3102
  sig { params(type: ::RBI::Type::Tuple).void }
3046
3103
  def visit_tuple(type); end
3047
3104
 
3105
+ sig { params(type: ::RBI::Type::TypeAlias).void }
3106
+ def visit_type_alias(type); end
3107
+
3048
3108
  sig { params(type: ::RBI::Type::TypeParameter).void }
3049
3109
  def visit_type_parameter(type); end
3050
3110
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
- rubygems_version: 3.6.9
99
+ rubygems_version: 3.7.2
100
100
  specification_version: 4
101
101
  summary: RBI generation framework
102
102
  test_files: []