rbi 0.2.4 → 0.3.2

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.
@@ -5,65 +5,70 @@ module RBI
5
5
  class RBSPrinter < Visitor
6
6
  class Error < RBI::Error; end
7
7
 
8
- sig { returns(T::Boolean) }
8
+ #: bool
9
9
  attr_accessor :print_locs, :in_visibility_group
10
10
 
11
- sig { returns(T.nilable(Node)) }
11
+ #: Node?
12
12
  attr_reader :previous_node
13
13
 
14
- sig { returns(Integer) }
14
+ #: Integer
15
15
  attr_reader :current_indent
16
16
 
17
- sig { params(out: T.any(IO, StringIO), indent: Integer, print_locs: T::Boolean).void }
18
- def initialize(out: $stdout, indent: 0, print_locs: false)
17
+ #: bool
18
+ attr_accessor :positional_names
19
+
20
+ #: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?positional_names: bool) -> void
21
+ def initialize(out: $stdout, indent: 0, print_locs: false, positional_names: true)
19
22
  super()
20
23
  @out = out
21
24
  @current_indent = indent
22
25
  @print_locs = print_locs
23
- @in_visibility_group = T.let(false, T::Boolean)
24
- @previous_node = T.let(nil, T.nilable(Node))
26
+ @in_visibility_group = false #: bool
27
+ @previous_node = nil #: Node?
28
+ @positional_names = positional_names #: bool
25
29
  end
26
30
 
27
31
  # Printing
28
32
 
29
- sig { void }
33
+ #: -> void
30
34
  def indent
31
35
  @current_indent += 2
32
36
  end
33
37
 
34
- sig { void }
38
+ #: -> void
35
39
  def dedent
36
40
  @current_indent -= 2
37
41
  end
38
42
 
39
43
  # Print a string without indentation nor `\n` at the end.
40
- sig { params(string: String).void }
44
+ #: (String string) -> void
41
45
  def print(string)
42
46
  @out.print(string)
43
47
  end
44
48
 
45
49
  # Print a string without indentation but with a `\n` at the end.
46
- sig { params(string: T.nilable(String)).void }
50
+ #: (?String? string) -> void
47
51
  def printn(string = nil)
48
52
  print(string) if string
49
53
  print("\n")
50
54
  end
51
55
 
52
56
  # Print a string with indentation but without a `\n` at the end.
53
- sig { params(string: T.nilable(String)).void }
57
+ #: (?String? string) -> void
54
58
  def printt(string = nil)
55
59
  print(" " * @current_indent)
56
60
  print(string) if string
57
61
  end
58
62
 
59
63
  # Print a string with indentation and `\n` at the end.
60
- sig { params(string: String).void }
64
+ #: (String string) -> void
61
65
  def printl(string)
62
66
  printt
63
67
  printn(string)
64
68
  end
65
69
 
66
- sig { override.params(nodes: T::Array[Node]).void }
70
+ # @override
71
+ #: (Array[Node] nodes) -> void
67
72
  def visit_all(nodes)
68
73
  previous_node = @previous_node
69
74
  @previous_node = nil
@@ -74,7 +79,8 @@ module RBI
74
79
  @previous_node = previous_node
75
80
  end
76
81
 
77
- sig { override.params(file: File).void }
82
+ # @override
83
+ #: (File file) -> void
78
84
  def visit_file(file)
79
85
  unless file.comments.empty?
80
86
  visit_all(file.comments)
@@ -86,7 +92,8 @@ module RBI
86
92
  end
87
93
  end
88
94
 
89
- sig { override.params(node: Comment).void }
95
+ # @override
96
+ #: (Comment node) -> void
90
97
  def visit_comment(node)
91
98
  lines = node.text.lines
92
99
 
@@ -102,39 +109,45 @@ module RBI
102
109
  end
103
110
  end
104
111
 
105
- sig { override.params(node: BlankLine).void }
112
+ # @override
113
+ #: (BlankLine node) -> void
106
114
  def visit_blank_line(node)
107
115
  printn
108
116
  end
109
117
 
110
- sig { override.params(node: Tree).void }
118
+ # @override
119
+ #: (Tree node) -> void
111
120
  def visit_tree(node)
112
121
  visit_all(node.comments)
113
122
  printn if !node.comments.empty? && !node.empty?
114
123
  visit_all(node.nodes)
115
124
  end
116
125
 
117
- sig { override.params(node: Module).void }
126
+ # @override
127
+ #: (Module node) -> void
118
128
  def visit_module(node)
119
129
  visit_scope(node)
120
130
  end
121
131
 
122
- sig { override.params(node: Class).void }
132
+ # @override
133
+ #: (Class node) -> void
123
134
  def visit_class(node)
124
135
  visit_scope(node)
125
136
  end
126
137
 
127
- sig { override.params(node: Struct).void }
138
+ # @override
139
+ #: (Struct node) -> void
128
140
  def visit_struct(node)
129
141
  visit_scope(node)
130
142
  end
131
143
 
132
- sig { override.params(node: SingletonClass).void }
144
+ # @override
145
+ #: (SingletonClass node) -> void
133
146
  def visit_singleton_class(node)
134
147
  visit_scope(node)
135
148
  end
136
149
 
137
- sig { params(node: Scope).void }
150
+ #: (Scope node) -> void
138
151
  def visit_scope(node)
139
152
  print_blank_line_before(node)
140
153
  print_loc(node)
@@ -144,7 +157,7 @@ module RBI
144
157
  visit_scope_body(node)
145
158
  end
146
159
 
147
- sig { params(node: Scope).void }
160
+ #: (Scope node) -> void
148
161
  def visit_scope_header(node)
149
162
  node.nodes.grep(Helper).each do |helper|
150
163
  visit(Comment.new("@#{helper.name}"))
@@ -197,7 +210,7 @@ module RBI
197
210
  printn
198
211
  end
199
212
 
200
- sig { params(node: Scope).void }
213
+ #: (Scope node) -> void
201
214
  def visit_scope_body(node)
202
215
  unless node.empty?
203
216
  indent
@@ -209,7 +222,8 @@ module RBI
209
222
  end
210
223
  end
211
224
 
212
- sig { override.params(node: Const).void }
225
+ # @override
226
+ #: (Const node) -> void
213
227
  def visit_const(node)
214
228
  print_blank_line_before(node)
215
229
  print_loc(node)
@@ -224,22 +238,25 @@ module RBI
224
238
  end
225
239
  end
226
240
 
227
- sig { override.params(node: AttrAccessor).void }
241
+ # @override
242
+ #: (AttrAccessor node) -> void
228
243
  def visit_attr_accessor(node)
229
244
  visit_attr(node)
230
245
  end
231
246
 
232
- sig { override.params(node: AttrReader).void }
247
+ # @override
248
+ #: (AttrReader node) -> void
233
249
  def visit_attr_reader(node)
234
250
  visit_attr(node)
235
251
  end
236
252
 
237
- sig { override.params(node: AttrWriter).void }
253
+ # @override
254
+ #: (AttrWriter node) -> void
238
255
  def visit_attr_writer(node)
239
256
  visit_attr(node)
240
257
  end
241
258
 
242
- sig { params(node: Attr).void }
259
+ #: (Attr node) -> void
243
260
  def visit_attr(node)
244
261
  print_blank_line_before(node)
245
262
 
@@ -271,7 +288,7 @@ module RBI
271
288
  end
272
289
  end
273
290
 
274
- sig { params(node: RBI::Attr, sig: Sig).void }
291
+ #: (RBI::Attr node, Sig sig) -> void
275
292
  def print_attr_sig(node, sig)
276
293
  ret_type = sig.return_type
277
294
 
@@ -293,7 +310,8 @@ module RBI
293
310
  print(type)
294
311
  end
295
312
 
296
- sig { override.params(node: Method).void }
313
+ # @override
314
+ #: (Method node) -> void
297
315
  def visit_method(node)
298
316
  print_blank_line_before(node)
299
317
  visit_all(node.comments)
@@ -331,7 +349,10 @@ module RBI
331
349
  print(": ")
332
350
  if sigs.any?
333
351
  first, *rest = sigs
334
- print_method_sig(node, T.must(first))
352
+ print_method_sig(
353
+ node,
354
+ first, #: as !nil
355
+ )
335
356
  if rest.any?
336
357
  spaces = node.name.size + 4
337
358
  rest.each do |sig|
@@ -359,7 +380,7 @@ module RBI
359
380
  printn
360
381
  end
361
382
 
362
- sig { params(node: RBI::Method, sig: Sig).void }
383
+ #: (RBI::Method node, Sig sig) -> void
363
384
  def print_method_sig(node, sig)
364
385
  unless sig.type_params.empty?
365
386
  print("[#{sig.type_params.join(", ")}] ")
@@ -421,7 +442,7 @@ module RBI
421
442
  print(" # #{loc}") if loc && print_locs
422
443
  end
423
444
 
424
- sig { params(node: Sig).void }
445
+ #: (Sig node) -> void
425
446
  def visit_sig(node)
426
447
  if node.params
427
448
  print("(")
@@ -434,57 +455,78 @@ module RBI
434
455
  print("-> #{parse_type(node.return_type).rbs_string}")
435
456
  end
436
457
 
437
- sig { params(node: SigParam).void }
458
+ #: (SigParam node) -> void
438
459
  def visit_sig_param(node)
439
460
  print(parse_type(node.type).rbs_string)
440
461
  end
441
462
 
442
- sig { override.params(node: ReqParam).void }
463
+ # @override
464
+ #: (ReqParam node) -> void
443
465
  def visit_req_param(node)
444
- print("untyped #{node.name}")
466
+ if @positional_names
467
+ print("untyped #{node.name}")
468
+ else
469
+ print("untyped")
470
+ end
445
471
  end
446
472
 
447
- sig { override.params(node: OptParam).void }
473
+ # @override
474
+ #: (OptParam node) -> void
448
475
  def visit_opt_param(node)
449
- print("?untyped #{node.name}")
476
+ if @positional_names
477
+ print("?untyped #{node.name}")
478
+ else
479
+ print("?untyped")
480
+ end
450
481
  end
451
482
 
452
- sig { override.params(node: RestParam).void }
483
+ # @override
484
+ #: (RestParam node) -> void
453
485
  def visit_rest_param(node)
454
- print("*untyped #{node.name}")
486
+ if @positional_names
487
+ print("*untyped #{node.name}")
488
+ else
489
+ print("*untyped")
490
+ end
455
491
  end
456
492
 
457
- sig { override.params(node: KwParam).void }
493
+ # @override
494
+ #: (KwParam node) -> void
458
495
  def visit_kw_param(node)
459
496
  print("#{node.name}: untyped")
460
497
  end
461
498
 
462
- sig { override.params(node: KwOptParam).void }
499
+ # @override
500
+ #: (KwOptParam node) -> void
463
501
  def visit_kw_opt_param(node)
464
502
  print("?#{node.name}: untyped")
465
503
  end
466
504
 
467
- sig { override.params(node: KwRestParam).void }
505
+ # @override
506
+ #: (KwRestParam node) -> void
468
507
  def visit_kw_rest_param(node)
469
508
  print("**#{node.name}: untyped")
470
509
  end
471
510
 
472
- sig { override.params(node: BlockParam).void }
511
+ # @override
512
+ #: (BlockParam node) -> void
473
513
  def visit_block_param(node)
474
514
  print("{ (*untyped) -> untyped } ")
475
515
  end
476
516
 
477
- sig { override.params(node: Include).void }
517
+ # @override
518
+ #: (Include node) -> void
478
519
  def visit_include(node)
479
520
  visit_mixin(node)
480
521
  end
481
522
 
482
- sig { override.params(node: Extend).void }
523
+ # @override
524
+ #: (Extend node) -> void
483
525
  def visit_extend(node)
484
526
  visit_mixin(node)
485
527
  end
486
528
 
487
- sig { params(node: Mixin).void }
529
+ #: (Mixin node) -> void
488
530
  def visit_mixin(node)
489
531
  return if node.is_a?(MixesInClassMethods) # no-op, `mixes_in_class_methods` is not supported in RBS
490
532
 
@@ -501,22 +543,25 @@ module RBI
501
543
  printn(" #{node.names.join(", ")}")
502
544
  end
503
545
 
504
- sig { override.params(node: Public).void }
546
+ # @override
547
+ #: (Public node) -> void
505
548
  def visit_public(node)
506
549
  visit_visibility(node)
507
550
  end
508
551
 
509
- sig { override.params(node: Protected).void }
552
+ # @override
553
+ #: (Protected node) -> void
510
554
  def visit_protected(node)
511
555
  # no-op, `protected` is not supported in RBS
512
556
  end
513
557
 
514
- sig { override.params(node: Private).void }
558
+ # @override
559
+ #: (Private node) -> void
515
560
  def visit_private(node)
516
561
  visit_visibility(node)
517
562
  end
518
563
 
519
- sig { params(node: Visibility).void }
564
+ #: (Visibility node) -> void
520
565
  def visit_visibility(node)
521
566
  print_blank_line_before(node)
522
567
  print_loc(node)
@@ -525,22 +570,26 @@ module RBI
525
570
  printl(node.visibility.to_s)
526
571
  end
527
572
 
528
- sig { override.params(node: Send).void }
573
+ # @override
574
+ #: (Send node) -> void
529
575
  def visit_send(node)
530
576
  # no-op, arbitrary sends are not supported in RBS
531
577
  end
532
578
 
533
- sig { override.params(node: Arg).void }
579
+ # @override
580
+ #: (Arg node) -> void
534
581
  def visit_arg(node)
535
582
  # no-op
536
583
  end
537
584
 
538
- sig { override.params(node: KwArg).void }
585
+ # @override
586
+ #: (KwArg node) -> void
539
587
  def visit_kw_arg(node)
540
588
  # no-op
541
589
  end
542
590
 
543
- sig { override.params(node: TStruct).void }
591
+ # @override
592
+ #: (TStruct node) -> void
544
593
  def visit_tstruct(node)
545
594
  print_blank_line_before(node)
546
595
  print_loc(node)
@@ -574,65 +623,77 @@ module RBI
574
623
  printl("end")
575
624
  end
576
625
 
577
- sig { override.params(node: TStructConst).void }
626
+ # @override
627
+ #: (TStructConst node) -> void
578
628
  def visit_tstruct_const(node)
579
629
  # `T::Struct.const` is not supported in RBS instead we generate an attribute reader
580
630
  accessor = AttrReader.new(node.name.to_sym, comments: node.comments, sigs: [Sig.new(return_type: node.type)])
581
631
  visit_attr_reader(accessor)
582
632
  end
583
633
 
584
- sig { override.params(node: TStructProp).void }
634
+ # @override
635
+ #: (TStructProp node) -> void
585
636
  def visit_tstruct_prop(node)
586
637
  # `T::Struct.prop` is not supported in RBS instead we generate an attribute accessor
587
638
  accessor = AttrAccessor.new(node.name.to_sym, comments: node.comments, sigs: [Sig.new(return_type: node.type)])
588
639
  visit_attr_accessor(accessor)
589
640
  end
590
641
 
591
- sig { override.params(node: TEnum).void }
642
+ # @override
643
+ #: (TEnum node) -> void
592
644
  def visit_tenum(node)
593
645
  visit_scope(node)
594
646
  end
595
647
 
596
- sig { override.params(node: TEnumBlock).void }
648
+ # @override
649
+ #: (TEnumBlock node) -> void
597
650
  def visit_tenum_block(node)
598
- node.nodes.each do |child|
599
- child = if child.is_a?(Const) && child.value == "new"
600
- parent = node.parent_scope
601
- Const.new(
602
- child.name,
603
- "T.let(nil, #{parent.is_a?(TEnum) ? parent.name : "T.untyped"})",
604
- comments: child.comments,
605
- )
606
- else
607
- child
608
- end
609
- visit(child)
610
- @previous_node = child
651
+ visit_all(node.nodes)
652
+ end
653
+
654
+ # @override
655
+ #: (TEnumValue node) -> void
656
+ def visit_tenum_value(node)
657
+ print_blank_line_before(node)
658
+ print_loc(node)
659
+ visit_all(node.comments)
660
+
661
+ t_enum = node.parent_scope&.parent_scope
662
+
663
+ if t_enum.is_a?(TEnum)
664
+ printl("#{node.name}: #{t_enum.name}")
665
+ else
666
+ printl("#{node.name}: untyped")
611
667
  end
612
668
  end
613
669
 
614
- sig { override.params(node: TypeMember).void }
670
+ # @override
671
+ #: (TypeMember node) -> void
615
672
  def visit_type_member(node)
616
673
  # no-op, we already show them in the scope header
617
674
  end
618
675
 
619
- sig { override.params(node: Helper).void }
676
+ # @override
677
+ #: (Helper node) -> void
620
678
  def visit_helper(node)
621
679
  # no-op, we already show them in the scope header
622
680
  end
623
681
 
624
- sig { override.params(node: MixesInClassMethods).void }
682
+ # @override
683
+ #: (MixesInClassMethods node) -> void
625
684
  def visit_mixes_in_class_methods(node)
626
685
  visit_mixin(node)
627
686
  end
628
687
 
629
- sig { override.params(node: Group).void }
688
+ # @override
689
+ #: (Group node) -> void
630
690
  def visit_group(node)
631
691
  printn unless previous_node.nil?
632
692
  visit_all(node.nodes)
633
693
  end
634
694
 
635
- sig { override.params(node: VisibilityGroup).void }
695
+ # @override
696
+ #: (VisibilityGroup node) -> void
636
697
  def visit_visibility_group(node)
637
698
  self.in_visibility_group = true
638
699
  if node.visibility.public?
@@ -645,12 +706,14 @@ module RBI
645
706
  self.in_visibility_group = false
646
707
  end
647
708
 
648
- sig { override.params(node: RequiresAncestor).void }
709
+ # @override
710
+ #: (RequiresAncestor node) -> void
649
711
  def visit_requires_ancestor(node)
650
712
  # no-op, we already show them in the scope header
651
713
  end
652
714
 
653
- sig { override.params(node: ConflictTree).void }
715
+ # @override
716
+ #: (ConflictTree node) -> void
654
717
  def visit_conflict_tree(node)
655
718
  printl("<<<<<<< #{node.left_name}")
656
719
  visit(node.left)
@@ -659,7 +722,8 @@ module RBI
659
722
  printl(">>>>>>> #{node.right_name}")
660
723
  end
661
724
 
662
- sig { override.params(node: ScopeConflict).void }
725
+ # @override
726
+ #: (ScopeConflict node) -> void
663
727
  def visit_scope_conflict(node)
664
728
  print_blank_line_before(node)
665
729
  print_loc(node)
@@ -675,7 +739,7 @@ module RBI
675
739
 
676
740
  private
677
741
 
678
- sig { params(node: Node).void }
742
+ #: (Node node) -> void
679
743
  def print_blank_line_before(node)
680
744
  previous_node = self.previous_node
681
745
  return unless previous_node
@@ -694,13 +758,13 @@ module RBI
694
758
  printn
695
759
  end
696
760
 
697
- sig { params(node: Node).void }
761
+ #: (Node node) -> void
698
762
  def print_loc(node)
699
763
  loc = node.loc
700
764
  printl("# #{loc}") if loc && print_locs
701
765
  end
702
766
 
703
- sig { params(node: Method, param: SigParam).void }
767
+ #: (Method node, SigParam param) -> void
704
768
  def print_sig_param(node, param)
705
769
  type = parse_type(param.type).rbs_string
706
770
 
@@ -708,11 +772,23 @@ module RBI
708
772
 
709
773
  case orig_param
710
774
  when ReqParam
711
- print("#{type} #{param.name}")
775
+ if @positional_names
776
+ print("#{type} #{param.name}")
777
+ else
778
+ print(type)
779
+ end
712
780
  when OptParam
713
- print("?#{type} #{param.name}")
781
+ if @positional_names
782
+ print("?#{type} #{param.name}")
783
+ else
784
+ print("?#{type}")
785
+ end
714
786
  when RestParam
715
- print("*#{type} #{param.name}")
787
+ if @positional_names
788
+ print("*#{type} #{param.name}")
789
+ else
790
+ print("*#{type}")
791
+ end
716
792
  when KwParam
717
793
  print("#{param.name}: #{type}")
718
794
  when KwOptParam
@@ -724,7 +800,7 @@ module RBI
724
800
  end
725
801
  end
726
802
 
727
- sig { params(node: Param, last: T::Boolean).void }
803
+ #: (Param node, last: bool) -> void
728
804
  def print_param_comment_leading_space(node, last:)
729
805
  printn
730
806
  printt
@@ -742,7 +818,7 @@ module RBI
742
818
  end
743
819
  end
744
820
 
745
- sig { params(node: SigParam, last: T::Boolean).void }
821
+ #: (SigParam node, last: bool) -> void
746
822
  def print_sig_param_comment_leading_space(node, last:)
747
823
  printn
748
824
  printt
@@ -750,7 +826,7 @@ module RBI
750
826
  print(" ") unless last
751
827
  end
752
828
 
753
- sig { params(node: Node).returns(T::Boolean) }
829
+ #: (Node node) -> bool
754
830
  def oneline?(node)
755
831
  case node
756
832
  when ScopeConflict
@@ -772,7 +848,7 @@ module RBI
772
848
  end
773
849
  end
774
850
 
775
- sig { params(type: T.any(Type, String)).returns(Type) }
851
+ #: ((Type | String) type) -> Type
776
852
  def parse_type(type)
777
853
  return type if type.is_a?(Type)
778
854
 
@@ -784,7 +860,7 @@ module RBI
784
860
  # Parse a string containing a `T.let(x, X)` and extract the type
785
861
  #
786
862
  # Returns `nil` is the string is not a `T.let`.
787
- sig { params(code: T.nilable(String)).returns(T.nilable(String)) }
863
+ #: (String? code) -> String?
788
864
  def parse_t_let(code)
789
865
  return unless code
790
866
 
@@ -807,17 +883,15 @@ module RBI
807
883
  end
808
884
 
809
885
  class TypePrinter
810
- extend T::Sig
811
-
812
- sig { returns(String) }
886
+ #: String
813
887
  attr_reader :string
814
888
 
815
- sig { void }
889
+ #: -> void
816
890
  def initialize
817
- @string = T.let(String.new, String)
891
+ @string = String.new #: String
818
892
  end
819
893
 
820
- sig { params(node: Type).void }
894
+ #: (Type node) -> void
821
895
  def visit(node)
822
896
  case node
823
897
  when Type::Simple
@@ -861,17 +935,17 @@ module RBI
861
935
  end
862
936
  end
863
937
 
864
- sig { params(type: Type::Simple).void }
938
+ #: (Type::Simple type) -> void
865
939
  def visit_simple(type)
866
940
  @string << translate_t_type(type.name.gsub(/\s/, ""))
867
941
  end
868
942
 
869
- sig { params(type: Type::Boolean).void }
943
+ #: (Type::Boolean type) -> void
870
944
  def visit_boolean(type)
871
945
  @string << "bool"
872
946
  end
873
947
 
874
- sig { params(type: Type::Generic).void }
948
+ #: (Type::Generic type) -> void
875
949
  def visit_generic(type)
876
950
  @string << translate_t_type(type.name.gsub(/\s/, ""))
877
951
  @string << "["
@@ -882,37 +956,37 @@ module RBI
882
956
  @string << "]"
883
957
  end
884
958
 
885
- sig { params(type: Type::Anything).void }
959
+ #: (Type::Anything type) -> void
886
960
  def visit_anything(type)
887
961
  @string << "top"
888
962
  end
889
963
 
890
- sig { params(type: Type::Void).void }
964
+ #: (Type::Void type) -> void
891
965
  def visit_void(type)
892
966
  @string << "void"
893
967
  end
894
968
 
895
- sig { params(type: Type::NoReturn).void }
969
+ #: (Type::NoReturn type) -> void
896
970
  def visit_no_return(type)
897
971
  @string << "bot"
898
972
  end
899
973
 
900
- sig { params(type: Type::Untyped).void }
974
+ #: (Type::Untyped type) -> void
901
975
  def visit_untyped(type)
902
976
  @string << "untyped"
903
977
  end
904
978
 
905
- sig { params(type: Type::SelfType).void }
979
+ #: (Type::SelfType type) -> void
906
980
  def visit_self_type(type)
907
981
  @string << "self"
908
982
  end
909
983
 
910
- sig { params(type: Type::AttachedClass).void }
984
+ #: (Type::AttachedClass type) -> void
911
985
  def visit_attached_class(type)
912
986
  @string << "instance"
913
987
  end
914
988
 
915
- sig { params(type: Type::Nilable).void }
989
+ #: (Type::Nilable type) -> void
916
990
  def visit_nilable(type)
917
991
  inner = type.type
918
992
  if inner.is_a?(Type::Proc)
@@ -925,14 +999,14 @@ module RBI
925
999
  @string << "?"
926
1000
  end
927
1001
 
928
- sig { params(type: Type::ClassOf).void }
1002
+ #: (Type::ClassOf type) -> void
929
1003
  def visit_class_of(type)
930
1004
  @string << "singleton("
931
1005
  visit(type.type)
932
1006
  @string << ")"
933
1007
  end
934
1008
 
935
- sig { params(type: Type::All).void }
1009
+ #: (Type::All type) -> void
936
1010
  def visit_all(type)
937
1011
  @string << "("
938
1012
  type.types.each_with_index do |arg, index|
@@ -942,7 +1016,7 @@ module RBI
942
1016
  @string << ")"
943
1017
  end
944
1018
 
945
- sig { params(type: Type::Any).void }
1019
+ #: (Type::Any type) -> void
946
1020
  def visit_any(type)
947
1021
  @string << "("
948
1022
  type.types.each_with_index do |arg, index|
@@ -952,7 +1026,7 @@ module RBI
952
1026
  @string << ")"
953
1027
  end
954
1028
 
955
- sig { params(type: Type::Tuple).void }
1029
+ #: (Type::Tuple type) -> void
956
1030
  def visit_tuple(type)
957
1031
  @string << "["
958
1032
  type.types.each_with_index do |arg, index|
@@ -962,7 +1036,7 @@ module RBI
962
1036
  @string << "]"
963
1037
  end
964
1038
 
965
- sig { params(type: Type::Shape).void }
1039
+ #: (Type::Shape type) -> void
966
1040
  def visit_shape(type)
967
1041
  @string << "{"
968
1042
  type.types.each_with_index do |(key, value), index|
@@ -982,7 +1056,7 @@ module RBI
982
1056
  @string << "}"
983
1057
  end
984
1058
 
985
- sig { params(type: Type::Proc).void }
1059
+ #: (Type::Proc type) -> void
986
1060
  def visit_proc(type)
987
1061
  @string << "^"
988
1062
  if type.proc_params.any?
@@ -1004,12 +1078,12 @@ module RBI
1004
1078
  visit(type.proc_returns)
1005
1079
  end
1006
1080
 
1007
- sig { params(type: Type::TypeParameter).void }
1081
+ #: (Type::TypeParameter type) -> void
1008
1082
  def visit_type_parameter(type)
1009
1083
  @string << type.name.to_s
1010
1084
  end
1011
1085
 
1012
- sig { params(type: Type::Class).void }
1086
+ #: (Type::Class type) -> void
1013
1087
  def visit_class(type)
1014
1088
  @string << "Class["
1015
1089
  visit(type.type)
@@ -1018,7 +1092,7 @@ module RBI
1018
1092
 
1019
1093
  private
1020
1094
 
1021
- sig { params(type_name: String).returns(String) }
1095
+ #: (String type_name) -> String
1022
1096
  def translate_t_type(type_name)
1023
1097
  case type_name
1024
1098
  when "T::Array"
@@ -1034,15 +1108,13 @@ module RBI
1034
1108
  end
1035
1109
 
1036
1110
  class File
1037
- extend T::Sig
1038
-
1039
- sig { params(out: T.any(IO, StringIO), indent: Integer, print_locs: T::Boolean).void }
1111
+ #: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool) -> void
1040
1112
  def rbs_print(out: $stdout, indent: 0, print_locs: false)
1041
1113
  p = RBSPrinter.new(out: out, indent: indent, print_locs: print_locs)
1042
1114
  p.visit_file(self)
1043
1115
  end
1044
1116
 
1045
- sig { params(indent: Integer, print_locs: T::Boolean).returns(String) }
1117
+ #: (?indent: Integer, ?print_locs: bool) -> String
1046
1118
  def rbs_string(indent: 0, print_locs: false)
1047
1119
  out = StringIO.new
1048
1120
  rbs_print(out: out, indent: indent, print_locs: print_locs)
@@ -1051,26 +1123,22 @@ module RBI
1051
1123
  end
1052
1124
 
1053
1125
  class Node
1054
- extend T::Sig
1055
-
1056
- sig { params(out: T.any(IO, StringIO), indent: Integer, print_locs: T::Boolean).void }
1057
- def rbs_print(out: $stdout, indent: 0, print_locs: false)
1058
- p = RBSPrinter.new(out: out, indent: indent, print_locs: print_locs)
1126
+ #: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?positional_names: bool) -> void
1127
+ def rbs_print(out: $stdout, indent: 0, print_locs: false, positional_names: true)
1128
+ p = RBSPrinter.new(out: out, indent: indent, print_locs: print_locs, positional_names: positional_names)
1059
1129
  p.visit(self)
1060
1130
  end
1061
1131
 
1062
- sig { params(indent: Integer, print_locs: T::Boolean).returns(String) }
1063
- def rbs_string(indent: 0, print_locs: false)
1132
+ #: (?indent: Integer, ?print_locs: bool, ?positional_names: bool) -> String
1133
+ def rbs_string(indent: 0, print_locs: false, positional_names: true)
1064
1134
  out = StringIO.new
1065
- rbs_print(out: out, indent: indent, print_locs: print_locs)
1135
+ rbs_print(out: out, indent: indent, print_locs: print_locs, positional_names: positional_names)
1066
1136
  out.string
1067
1137
  end
1068
1138
  end
1069
1139
 
1070
1140
  class Type
1071
- extend T::Sig
1072
-
1073
- sig { returns(String) }
1141
+ #: -> String
1074
1142
  def rbs_string
1075
1143
  p = TypePrinter.new
1076
1144
  p.visit(self)