rbi 0.2.4 → 0.3.0

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
26
  @in_visibility_group = T.let(false, T::Boolean)
24
27
  @previous_node = T.let(nil, T.nilable(Node))
28
+ @positional_names = T.let(positional_names, T::Boolean)
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)
@@ -359,7 +377,7 @@ module RBI
359
377
  printn
360
378
  end
361
379
 
362
- sig { params(node: RBI::Method, sig: Sig).void }
380
+ #: (RBI::Method node, Sig sig) -> void
363
381
  def print_method_sig(node, sig)
364
382
  unless sig.type_params.empty?
365
383
  print("[#{sig.type_params.join(", ")}] ")
@@ -421,7 +439,7 @@ module RBI
421
439
  print(" # #{loc}") if loc && print_locs
422
440
  end
423
441
 
424
- sig { params(node: Sig).void }
442
+ #: (Sig node) -> void
425
443
  def visit_sig(node)
426
444
  if node.params
427
445
  print("(")
@@ -434,57 +452,78 @@ module RBI
434
452
  print("-> #{parse_type(node.return_type).rbs_string}")
435
453
  end
436
454
 
437
- sig { params(node: SigParam).void }
455
+ #: (SigParam node) -> void
438
456
  def visit_sig_param(node)
439
457
  print(parse_type(node.type).rbs_string)
440
458
  end
441
459
 
442
- sig { override.params(node: ReqParam).void }
460
+ # @override
461
+ #: (ReqParam node) -> void
443
462
  def visit_req_param(node)
444
- print("untyped #{node.name}")
463
+ if @positional_names
464
+ print("untyped #{node.name}")
465
+ else
466
+ print("untyped")
467
+ end
445
468
  end
446
469
 
447
- sig { override.params(node: OptParam).void }
470
+ # @override
471
+ #: (OptParam node) -> void
448
472
  def visit_opt_param(node)
449
- print("?untyped #{node.name}")
473
+ if @positional_names
474
+ print("?untyped #{node.name}")
475
+ else
476
+ print("?untyped")
477
+ end
450
478
  end
451
479
 
452
- sig { override.params(node: RestParam).void }
480
+ # @override
481
+ #: (RestParam node) -> void
453
482
  def visit_rest_param(node)
454
- print("*untyped #{node.name}")
483
+ if @positional_names
484
+ print("*untyped #{node.name}")
485
+ else
486
+ print("*untyped")
487
+ end
455
488
  end
456
489
 
457
- sig { override.params(node: KwParam).void }
490
+ # @override
491
+ #: (KwParam node) -> void
458
492
  def visit_kw_param(node)
459
493
  print("#{node.name}: untyped")
460
494
  end
461
495
 
462
- sig { override.params(node: KwOptParam).void }
496
+ # @override
497
+ #: (KwOptParam node) -> void
463
498
  def visit_kw_opt_param(node)
464
499
  print("?#{node.name}: untyped")
465
500
  end
466
501
 
467
- sig { override.params(node: KwRestParam).void }
502
+ # @override
503
+ #: (KwRestParam node) -> void
468
504
  def visit_kw_rest_param(node)
469
505
  print("**#{node.name}: untyped")
470
506
  end
471
507
 
472
- sig { override.params(node: BlockParam).void }
508
+ # @override
509
+ #: (BlockParam node) -> void
473
510
  def visit_block_param(node)
474
511
  print("{ (*untyped) -> untyped } ")
475
512
  end
476
513
 
477
- sig { override.params(node: Include).void }
514
+ # @override
515
+ #: (Include node) -> void
478
516
  def visit_include(node)
479
517
  visit_mixin(node)
480
518
  end
481
519
 
482
- sig { override.params(node: Extend).void }
520
+ # @override
521
+ #: (Extend node) -> void
483
522
  def visit_extend(node)
484
523
  visit_mixin(node)
485
524
  end
486
525
 
487
- sig { params(node: Mixin).void }
526
+ #: (Mixin node) -> void
488
527
  def visit_mixin(node)
489
528
  return if node.is_a?(MixesInClassMethods) # no-op, `mixes_in_class_methods` is not supported in RBS
490
529
 
@@ -501,22 +540,25 @@ module RBI
501
540
  printn(" #{node.names.join(", ")}")
502
541
  end
503
542
 
504
- sig { override.params(node: Public).void }
543
+ # @override
544
+ #: (Public node) -> void
505
545
  def visit_public(node)
506
546
  visit_visibility(node)
507
547
  end
508
548
 
509
- sig { override.params(node: Protected).void }
549
+ # @override
550
+ #: (Protected node) -> void
510
551
  def visit_protected(node)
511
552
  # no-op, `protected` is not supported in RBS
512
553
  end
513
554
 
514
- sig { override.params(node: Private).void }
555
+ # @override
556
+ #: (Private node) -> void
515
557
  def visit_private(node)
516
558
  visit_visibility(node)
517
559
  end
518
560
 
519
- sig { params(node: Visibility).void }
561
+ #: (Visibility node) -> void
520
562
  def visit_visibility(node)
521
563
  print_blank_line_before(node)
522
564
  print_loc(node)
@@ -525,22 +567,26 @@ module RBI
525
567
  printl(node.visibility.to_s)
526
568
  end
527
569
 
528
- sig { override.params(node: Send).void }
570
+ # @override
571
+ #: (Send node) -> void
529
572
  def visit_send(node)
530
573
  # no-op, arbitrary sends are not supported in RBS
531
574
  end
532
575
 
533
- sig { override.params(node: Arg).void }
576
+ # @override
577
+ #: (Arg node) -> void
534
578
  def visit_arg(node)
535
579
  # no-op
536
580
  end
537
581
 
538
- sig { override.params(node: KwArg).void }
582
+ # @override
583
+ #: (KwArg node) -> void
539
584
  def visit_kw_arg(node)
540
585
  # no-op
541
586
  end
542
587
 
543
- sig { override.params(node: TStruct).void }
588
+ # @override
589
+ #: (TStruct node) -> void
544
590
  def visit_tstruct(node)
545
591
  print_blank_line_before(node)
546
592
  print_loc(node)
@@ -574,26 +620,30 @@ module RBI
574
620
  printl("end")
575
621
  end
576
622
 
577
- sig { override.params(node: TStructConst).void }
623
+ # @override
624
+ #: (TStructConst node) -> void
578
625
  def visit_tstruct_const(node)
579
626
  # `T::Struct.const` is not supported in RBS instead we generate an attribute reader
580
627
  accessor = AttrReader.new(node.name.to_sym, comments: node.comments, sigs: [Sig.new(return_type: node.type)])
581
628
  visit_attr_reader(accessor)
582
629
  end
583
630
 
584
- sig { override.params(node: TStructProp).void }
631
+ # @override
632
+ #: (TStructProp node) -> void
585
633
  def visit_tstruct_prop(node)
586
634
  # `T::Struct.prop` is not supported in RBS instead we generate an attribute accessor
587
635
  accessor = AttrAccessor.new(node.name.to_sym, comments: node.comments, sigs: [Sig.new(return_type: node.type)])
588
636
  visit_attr_accessor(accessor)
589
637
  end
590
638
 
591
- sig { override.params(node: TEnum).void }
639
+ # @override
640
+ #: (TEnum node) -> void
592
641
  def visit_tenum(node)
593
642
  visit_scope(node)
594
643
  end
595
644
 
596
- sig { override.params(node: TEnumBlock).void }
645
+ # @override
646
+ #: (TEnumBlock node) -> void
597
647
  def visit_tenum_block(node)
598
648
  node.nodes.each do |child|
599
649
  child = if child.is_a?(Const) && child.value == "new"
@@ -611,28 +661,33 @@ module RBI
611
661
  end
612
662
  end
613
663
 
614
- sig { override.params(node: TypeMember).void }
664
+ # @override
665
+ #: (TypeMember node) -> void
615
666
  def visit_type_member(node)
616
667
  # no-op, we already show them in the scope header
617
668
  end
618
669
 
619
- sig { override.params(node: Helper).void }
670
+ # @override
671
+ #: (Helper node) -> void
620
672
  def visit_helper(node)
621
673
  # no-op, we already show them in the scope header
622
674
  end
623
675
 
624
- sig { override.params(node: MixesInClassMethods).void }
676
+ # @override
677
+ #: (MixesInClassMethods node) -> void
625
678
  def visit_mixes_in_class_methods(node)
626
679
  visit_mixin(node)
627
680
  end
628
681
 
629
- sig { override.params(node: Group).void }
682
+ # @override
683
+ #: (Group node) -> void
630
684
  def visit_group(node)
631
685
  printn unless previous_node.nil?
632
686
  visit_all(node.nodes)
633
687
  end
634
688
 
635
- sig { override.params(node: VisibilityGroup).void }
689
+ # @override
690
+ #: (VisibilityGroup node) -> void
636
691
  def visit_visibility_group(node)
637
692
  self.in_visibility_group = true
638
693
  if node.visibility.public?
@@ -645,12 +700,14 @@ module RBI
645
700
  self.in_visibility_group = false
646
701
  end
647
702
 
648
- sig { override.params(node: RequiresAncestor).void }
703
+ # @override
704
+ #: (RequiresAncestor node) -> void
649
705
  def visit_requires_ancestor(node)
650
706
  # no-op, we already show them in the scope header
651
707
  end
652
708
 
653
- sig { override.params(node: ConflictTree).void }
709
+ # @override
710
+ #: (ConflictTree node) -> void
654
711
  def visit_conflict_tree(node)
655
712
  printl("<<<<<<< #{node.left_name}")
656
713
  visit(node.left)
@@ -659,7 +716,8 @@ module RBI
659
716
  printl(">>>>>>> #{node.right_name}")
660
717
  end
661
718
 
662
- sig { override.params(node: ScopeConflict).void }
719
+ # @override
720
+ #: (ScopeConflict node) -> void
663
721
  def visit_scope_conflict(node)
664
722
  print_blank_line_before(node)
665
723
  print_loc(node)
@@ -675,7 +733,7 @@ module RBI
675
733
 
676
734
  private
677
735
 
678
- sig { params(node: Node).void }
736
+ #: (Node node) -> void
679
737
  def print_blank_line_before(node)
680
738
  previous_node = self.previous_node
681
739
  return unless previous_node
@@ -694,13 +752,13 @@ module RBI
694
752
  printn
695
753
  end
696
754
 
697
- sig { params(node: Node).void }
755
+ #: (Node node) -> void
698
756
  def print_loc(node)
699
757
  loc = node.loc
700
758
  printl("# #{loc}") if loc && print_locs
701
759
  end
702
760
 
703
- sig { params(node: Method, param: SigParam).void }
761
+ #: (Method node, SigParam param) -> void
704
762
  def print_sig_param(node, param)
705
763
  type = parse_type(param.type).rbs_string
706
764
 
@@ -708,11 +766,23 @@ module RBI
708
766
 
709
767
  case orig_param
710
768
  when ReqParam
711
- print("#{type} #{param.name}")
769
+ if @positional_names
770
+ print("#{type} #{param.name}")
771
+ else
772
+ print(type)
773
+ end
712
774
  when OptParam
713
- print("?#{type} #{param.name}")
775
+ if @positional_names
776
+ print("?#{type} #{param.name}")
777
+ else
778
+ print("?#{type}")
779
+ end
714
780
  when RestParam
715
- print("*#{type} #{param.name}")
781
+ if @positional_names
782
+ print("*#{type} #{param.name}")
783
+ else
784
+ print("*#{type}")
785
+ end
716
786
  when KwParam
717
787
  print("#{param.name}: #{type}")
718
788
  when KwOptParam
@@ -724,7 +794,7 @@ module RBI
724
794
  end
725
795
  end
726
796
 
727
- sig { params(node: Param, last: T::Boolean).void }
797
+ #: (Param node, last: bool) -> void
728
798
  def print_param_comment_leading_space(node, last:)
729
799
  printn
730
800
  printt
@@ -742,7 +812,7 @@ module RBI
742
812
  end
743
813
  end
744
814
 
745
- sig { params(node: SigParam, last: T::Boolean).void }
815
+ #: (SigParam node, last: bool) -> void
746
816
  def print_sig_param_comment_leading_space(node, last:)
747
817
  printn
748
818
  printt
@@ -750,7 +820,7 @@ module RBI
750
820
  print(" ") unless last
751
821
  end
752
822
 
753
- sig { params(node: Node).returns(T::Boolean) }
823
+ #: (Node node) -> bool
754
824
  def oneline?(node)
755
825
  case node
756
826
  when ScopeConflict
@@ -772,7 +842,7 @@ module RBI
772
842
  end
773
843
  end
774
844
 
775
- sig { params(type: T.any(Type, String)).returns(Type) }
845
+ #: ((Type | String) type) -> Type
776
846
  def parse_type(type)
777
847
  return type if type.is_a?(Type)
778
848
 
@@ -784,7 +854,7 @@ module RBI
784
854
  # Parse a string containing a `T.let(x, X)` and extract the type
785
855
  #
786
856
  # Returns `nil` is the string is not a `T.let`.
787
- sig { params(code: T.nilable(String)).returns(T.nilable(String)) }
857
+ #: (String? code) -> String?
788
858
  def parse_t_let(code)
789
859
  return unless code
790
860
 
@@ -807,17 +877,15 @@ module RBI
807
877
  end
808
878
 
809
879
  class TypePrinter
810
- extend T::Sig
811
-
812
- sig { returns(String) }
880
+ #: String
813
881
  attr_reader :string
814
882
 
815
- sig { void }
883
+ #: -> void
816
884
  def initialize
817
885
  @string = T.let(String.new, String)
818
886
  end
819
887
 
820
- sig { params(node: Type).void }
888
+ #: (Type node) -> void
821
889
  def visit(node)
822
890
  case node
823
891
  when Type::Simple
@@ -861,17 +929,17 @@ module RBI
861
929
  end
862
930
  end
863
931
 
864
- sig { params(type: Type::Simple).void }
932
+ #: (Type::Simple type) -> void
865
933
  def visit_simple(type)
866
934
  @string << translate_t_type(type.name.gsub(/\s/, ""))
867
935
  end
868
936
 
869
- sig { params(type: Type::Boolean).void }
937
+ #: (Type::Boolean type) -> void
870
938
  def visit_boolean(type)
871
939
  @string << "bool"
872
940
  end
873
941
 
874
- sig { params(type: Type::Generic).void }
942
+ #: (Type::Generic type) -> void
875
943
  def visit_generic(type)
876
944
  @string << translate_t_type(type.name.gsub(/\s/, ""))
877
945
  @string << "["
@@ -882,37 +950,37 @@ module RBI
882
950
  @string << "]"
883
951
  end
884
952
 
885
- sig { params(type: Type::Anything).void }
953
+ #: (Type::Anything type) -> void
886
954
  def visit_anything(type)
887
955
  @string << "top"
888
956
  end
889
957
 
890
- sig { params(type: Type::Void).void }
958
+ #: (Type::Void type) -> void
891
959
  def visit_void(type)
892
960
  @string << "void"
893
961
  end
894
962
 
895
- sig { params(type: Type::NoReturn).void }
963
+ #: (Type::NoReturn type) -> void
896
964
  def visit_no_return(type)
897
965
  @string << "bot"
898
966
  end
899
967
 
900
- sig { params(type: Type::Untyped).void }
968
+ #: (Type::Untyped type) -> void
901
969
  def visit_untyped(type)
902
970
  @string << "untyped"
903
971
  end
904
972
 
905
- sig { params(type: Type::SelfType).void }
973
+ #: (Type::SelfType type) -> void
906
974
  def visit_self_type(type)
907
975
  @string << "self"
908
976
  end
909
977
 
910
- sig { params(type: Type::AttachedClass).void }
978
+ #: (Type::AttachedClass type) -> void
911
979
  def visit_attached_class(type)
912
980
  @string << "instance"
913
981
  end
914
982
 
915
- sig { params(type: Type::Nilable).void }
983
+ #: (Type::Nilable type) -> void
916
984
  def visit_nilable(type)
917
985
  inner = type.type
918
986
  if inner.is_a?(Type::Proc)
@@ -925,14 +993,14 @@ module RBI
925
993
  @string << "?"
926
994
  end
927
995
 
928
- sig { params(type: Type::ClassOf).void }
996
+ #: (Type::ClassOf type) -> void
929
997
  def visit_class_of(type)
930
998
  @string << "singleton("
931
999
  visit(type.type)
932
1000
  @string << ")"
933
1001
  end
934
1002
 
935
- sig { params(type: Type::All).void }
1003
+ #: (Type::All type) -> void
936
1004
  def visit_all(type)
937
1005
  @string << "("
938
1006
  type.types.each_with_index do |arg, index|
@@ -942,7 +1010,7 @@ module RBI
942
1010
  @string << ")"
943
1011
  end
944
1012
 
945
- sig { params(type: Type::Any).void }
1013
+ #: (Type::Any type) -> void
946
1014
  def visit_any(type)
947
1015
  @string << "("
948
1016
  type.types.each_with_index do |arg, index|
@@ -952,7 +1020,7 @@ module RBI
952
1020
  @string << ")"
953
1021
  end
954
1022
 
955
- sig { params(type: Type::Tuple).void }
1023
+ #: (Type::Tuple type) -> void
956
1024
  def visit_tuple(type)
957
1025
  @string << "["
958
1026
  type.types.each_with_index do |arg, index|
@@ -962,7 +1030,7 @@ module RBI
962
1030
  @string << "]"
963
1031
  end
964
1032
 
965
- sig { params(type: Type::Shape).void }
1033
+ #: (Type::Shape type) -> void
966
1034
  def visit_shape(type)
967
1035
  @string << "{"
968
1036
  type.types.each_with_index do |(key, value), index|
@@ -982,7 +1050,7 @@ module RBI
982
1050
  @string << "}"
983
1051
  end
984
1052
 
985
- sig { params(type: Type::Proc).void }
1053
+ #: (Type::Proc type) -> void
986
1054
  def visit_proc(type)
987
1055
  @string << "^"
988
1056
  if type.proc_params.any?
@@ -1004,12 +1072,12 @@ module RBI
1004
1072
  visit(type.proc_returns)
1005
1073
  end
1006
1074
 
1007
- sig { params(type: Type::TypeParameter).void }
1075
+ #: (Type::TypeParameter type) -> void
1008
1076
  def visit_type_parameter(type)
1009
1077
  @string << type.name.to_s
1010
1078
  end
1011
1079
 
1012
- sig { params(type: Type::Class).void }
1080
+ #: (Type::Class type) -> void
1013
1081
  def visit_class(type)
1014
1082
  @string << "Class["
1015
1083
  visit(type.type)
@@ -1018,7 +1086,7 @@ module RBI
1018
1086
 
1019
1087
  private
1020
1088
 
1021
- sig { params(type_name: String).returns(String) }
1089
+ #: (String type_name) -> String
1022
1090
  def translate_t_type(type_name)
1023
1091
  case type_name
1024
1092
  when "T::Array"
@@ -1034,15 +1102,13 @@ module RBI
1034
1102
  end
1035
1103
 
1036
1104
  class File
1037
- extend T::Sig
1038
-
1039
- sig { params(out: T.any(IO, StringIO), indent: Integer, print_locs: T::Boolean).void }
1105
+ #: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool) -> void
1040
1106
  def rbs_print(out: $stdout, indent: 0, print_locs: false)
1041
1107
  p = RBSPrinter.new(out: out, indent: indent, print_locs: print_locs)
1042
1108
  p.visit_file(self)
1043
1109
  end
1044
1110
 
1045
- sig { params(indent: Integer, print_locs: T::Boolean).returns(String) }
1111
+ #: (?indent: Integer, ?print_locs: bool) -> String
1046
1112
  def rbs_string(indent: 0, print_locs: false)
1047
1113
  out = StringIO.new
1048
1114
  rbs_print(out: out, indent: indent, print_locs: print_locs)
@@ -1051,26 +1117,22 @@ module RBI
1051
1117
  end
1052
1118
 
1053
1119
  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)
1120
+ #: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?positional_names: bool) -> void
1121
+ def rbs_print(out: $stdout, indent: 0, print_locs: false, positional_names: true)
1122
+ p = RBSPrinter.new(out: out, indent: indent, print_locs: print_locs, positional_names: positional_names)
1059
1123
  p.visit(self)
1060
1124
  end
1061
1125
 
1062
- sig { params(indent: Integer, print_locs: T::Boolean).returns(String) }
1063
- def rbs_string(indent: 0, print_locs: false)
1126
+ #: (?indent: Integer, ?print_locs: bool, ?positional_names: bool) -> String
1127
+ def rbs_string(indent: 0, print_locs: false, positional_names: true)
1064
1128
  out = StringIO.new
1065
- rbs_print(out: out, indent: indent, print_locs: print_locs)
1129
+ rbs_print(out: out, indent: indent, print_locs: print_locs, positional_names: positional_names)
1066
1130
  out.string
1067
1131
  end
1068
1132
  end
1069
1133
 
1070
1134
  class Type
1071
- extend T::Sig
1072
-
1073
- sig { returns(String) }
1135
+ #: -> String
1074
1136
  def rbs_string
1075
1137
  p = TypePrinter.new
1076
1138
  p.visit(self)