rbi 0.3.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a3e133057e9df490de9a0757b30f9b1f19ffa3afbca8f16c55c90e1562bffd7
4
- data.tar.gz: 835d569c6d20336e4911ef660117cb03af2b5c312e04850058b34402ba94cc34
3
+ metadata.gz: 30c1564f6fad1d76035f6cd07bf31237251e6c622350aa4911797980b3a17414
4
+ data.tar.gz: 1d1350fa25cf2dad93c59e74288372701bfe73c6214d46e279350a953269786d
5
5
  SHA512:
6
- metadata.gz: 6c7d07ae2efbeee1310c61d0fdf440408e755d38febc3ed30a194512df118845d36ea9315142b87239ff1f8856f045bc565ac975683a504c05b05792aed9c4f8
7
- data.tar.gz: 9661b08e169d35d2f947e88de33360bd8ba6d5ee522a2b8beccd77c6589bd6ed1fd560c7a665201c8e8d5869f7a8dda872c58fc0009acf6eda86b3e1da0a1fd9
6
+ metadata.gz: a273b8f7e57c8471e8a9d46f71c7b554e2416243e7ef1c953137720543f7dd70f4166b0c916e327dcb9cf516e0668deaf56027ade2c36485f9fce10cfedb9d9d
7
+ data.tar.gz: e03adcd232b2557c68d6a18a62c0e0b1977e8f4cccb3a8718f711ae2ec35ded301026021a7d39829da51286348089cdde3593d0b3bb1703da8d69a86af6364c5
data/Gemfile CHANGED
@@ -10,9 +10,10 @@ group(:development, :test) do
10
10
  gem("minitest")
11
11
  gem("minitest-reporters")
12
12
  gem("rake", "~> 13.2")
13
- gem("rubocop", "~> 1.73", require: false)
13
+ gem("rubocop", "~> 1.75", 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)
17
+ gem("spoom", ">= 1.6.0", require: false)
17
18
  gem("tapioca", require: false)
18
19
  end
data/lib/rbi/formatter.rb CHANGED
@@ -6,14 +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) -> void
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
10
10
  def initialize(
11
11
  add_sig_templates: false,
12
12
  group_nodes: false,
13
13
  max_line_length: nil,
14
14
  nest_singleton_methods: false,
15
15
  nest_non_public_members: false,
16
- sort_nodes: false
16
+ sort_nodes: false,
17
+ replace_attributes_with_methods: false
17
18
  )
18
19
  @add_sig_templates = add_sig_templates
19
20
  @group_nodes = group_nodes
@@ -21,6 +22,7 @@ module RBI
21
22
  @nest_singleton_methods = nest_singleton_methods
22
23
  @nest_non_public_members = nest_non_public_members
23
24
  @sort_nodes = sort_nodes
25
+ @replace_attributes_with_methods = replace_attributes_with_methods
24
26
  end
25
27
 
26
28
  #: (RBI::File file) -> String
@@ -36,6 +38,7 @@ module RBI
36
38
 
37
39
  #: (RBI::Tree tree) -> void
38
40
  def format_tree(tree)
41
+ tree.replace_attributes_with_methods! if @replace_attributes_with_methods
39
42
  tree.add_sig_templates! if @add_sig_templates
40
43
  tree.nest_singleton_methods! if @nest_singleton_methods
41
44
  tree.nest_non_public_members! if @nest_non_public_members
data/lib/rbi/index.rb CHANGED
@@ -17,7 +17,7 @@ module RBI
17
17
  #: -> void
18
18
  def initialize
19
19
  super
20
- @index = T.let({}, T::Hash[String, T::Array[Node]])
20
+ @index = {} #: Hash[String, Array[Node]]
21
21
  end
22
22
 
23
23
  #: -> Array[String]
@@ -217,7 +217,17 @@ module RBI
217
217
  # @override
218
218
  #: -> Array[String]
219
219
  def index_ids
220
- [to_s]
220
+ [fully_qualified_name]
221
+ end
222
+ end
223
+
224
+ class TEnumValue
225
+ include Indexable
226
+
227
+ # @override
228
+ #: -> Array[String]
229
+ def index_ids
230
+ [fully_qualified_name]
221
231
  end
222
232
  end
223
233
  end
data/lib/rbi/loc.rb CHANGED
@@ -50,7 +50,7 @@ module RBI
50
50
 
51
51
  string = String.new
52
52
  ::File.foreach(file).with_index do |line, line_number|
53
- string << line if line_number + 1 >= begin_line && line_number + 1 <= end_line
53
+ string << line if (line_number + 1).between?(begin_line, end_line)
54
54
  end
55
55
  string
56
56
  end
data/lib/rbi/model.rb CHANGED
@@ -45,7 +45,7 @@ module RBI
45
45
 
46
46
  #: -> Scope?
47
47
  def parent_scope
48
- parent = T.let(parent_tree, T.nilable(Tree))
48
+ parent = parent_tree #: Tree?
49
49
  parent = parent.parent_tree until parent.is_a?(Scope) || parent.nil?
50
50
  parent
51
51
  end
@@ -105,7 +105,9 @@ module RBI
105
105
  def annotations
106
106
  comments
107
107
  .select { |comment| comment.text.start_with?("@") }
108
- .map { |comment| T.must(comment.text[1..]) }
108
+ .map do |comment|
109
+ comment.text[1..] #: as !nil
110
+ end
109
111
  end
110
112
  end
111
113
 
@@ -116,7 +118,7 @@ module RBI
116
118
  #: (?loc: Loc?, ?comments: Array[Comment]) ?{ (Tree node) -> void } -> void
117
119
  def initialize(loc: nil, comments: [], &block)
118
120
  super(loc: loc, comments: comments)
119
- @nodes = T.let([], T::Array[Node])
121
+ @nodes = [] #: Array[Node]
120
122
  block&.call(self)
121
123
  end
122
124
 
@@ -144,7 +146,7 @@ module RBI
144
146
 
145
147
  #: (?strictness: String?, ?comments: Array[Comment]) ?{ (File file) -> void } -> void
146
148
  def initialize(strictness: nil, comments: [], &block)
147
- @root = T.let(Tree.new, Tree)
149
+ @root = Tree.new #: Tree
148
150
  @strictness = strictness
149
151
  @comments = comments
150
152
  block&.call(self)
@@ -313,7 +315,7 @@ module RBI
313
315
  #: (Symbol name, Array[Symbol] names, ?visibility: Visibility, ?sigs: Array[Sig], ?loc: Loc?, ?comments: Array[Comment]) -> void
314
316
  def initialize(name, names, visibility: Public.new, sigs: [], loc: nil, comments: [])
315
317
  super(loc: loc, comments: comments)
316
- @names = T.let([name, *names], T::Array[Symbol])
318
+ @names = [name, *names] #: Array[Symbol]
317
319
  @visibility = visibility
318
320
  @sigs = sigs
319
321
  end
@@ -671,7 +673,7 @@ module RBI
671
673
  #: (String name, Array[String] names, ?loc: Loc?, ?comments: Array[Comment]) -> void
672
674
  def initialize(name, names, loc: nil, comments: [])
673
675
  super(loc: loc, comments: comments)
674
- @names = T.let([name, *names], T::Array[String])
676
+ @names = [name, *names] #: Array[String]
675
677
  end
676
678
  end
677
679
 
@@ -1037,6 +1039,29 @@ module RBI
1037
1039
  end
1038
1040
  end
1039
1041
 
1042
+ class TEnumValue < NodeWithComments
1043
+ #: String
1044
+ attr_reader :name
1045
+
1046
+ #: (String name, ?loc: Loc?, ?comments: Array[Comment]) ?{ (TEnumValue node) -> void } -> void
1047
+ def initialize(name, loc: nil, comments: [], &block)
1048
+ super(loc: loc, comments: comments)
1049
+ @name = name
1050
+ block&.call(self)
1051
+ end
1052
+
1053
+ #: -> String
1054
+ def fully_qualified_name
1055
+ "#{parent_scope&.fully_qualified_name}::#{name}"
1056
+ end
1057
+
1058
+ # @override
1059
+ #: -> String
1060
+ def to_s
1061
+ fully_qualified_name
1062
+ end
1063
+ end
1064
+
1040
1065
  # Sorbet's misc.
1041
1066
 
1042
1067
  class Helper < NodeWithComments
data/lib/rbi/parser.rb CHANGED
@@ -136,7 +136,18 @@ module RBI
136
136
 
137
137
  #: (Prism::Node node) -> String
138
138
  def node_string!(node)
139
- T.must(node_string(node))
139
+ node_string(node) #: as !nil
140
+ end
141
+
142
+ #: (Prism::Node node) -> Prism::Location
143
+ def adjust_prism_location_for_heredoc(node)
144
+ visitor = HeredocLocationVisitor.new(
145
+ node.location.send(:source),
146
+ node.location.start_offset,
147
+ node.location.end_offset,
148
+ )
149
+ visitor.visit(node)
150
+ visitor.location
140
151
  end
141
152
  end
142
153
 
@@ -151,12 +162,12 @@ module RBI
151
162
  def initialize(source, comments:, file:)
152
163
  super(source, file: file)
153
164
 
154
- @comments_by_line = T.let(comments.to_h { |c| [c.location.start_line, c] }, T::Hash[Integer, Prism::Comment])
155
- @tree = T.let(Tree.new, Tree)
165
+ @comments_by_line = comments.to_h { |c| [c.location.start_line, c] } #: Hash[Integer, Prism::Comment]
166
+ @tree = Tree.new #: Tree
156
167
 
157
- @scopes_stack = T.let([@tree], T::Array[Tree])
158
- @last_node = T.let(nil, T.nilable(Prism::Node))
159
- @last_sigs = T.let([], T::Array[RBI::Sig])
168
+ @scopes_stack = [@tree] #: Array[Tree]
169
+ @last_node = nil #: Prism::Node?
170
+ @last_sigs = [] #: Array[RBI::Sig]
160
171
  end
161
172
 
162
173
  # @override
@@ -217,30 +228,51 @@ module RBI
217
228
 
218
229
  current_scope << if struct
219
230
  struct
220
- elsif type_variable_definition?(node.value)
221
- TypeMember.new(
231
+ elsif t_enum_value?(node)
232
+ TEnumValue.new(
222
233
  case node
223
234
  when Prism::ConstantWriteNode
224
235
  node.name.to_s
225
236
  when Prism::ConstantPathWriteNode
226
237
  node_string!(node.target)
227
238
  end,
228
- node_string!(node.value),
229
239
  loc: node_loc(node),
230
240
  comments: node_comments(node),
231
241
  )
232
242
  else
233
- Const.new(
234
- case node
235
- when Prism::ConstantWriteNode
236
- node.name.to_s
237
- when Prism::ConstantPathWriteNode
238
- node_string!(node.target)
239
- end,
240
- node_string!(node.value),
241
- loc: node_loc(node),
242
- comments: node_comments(node),
243
+ adjusted_node_location = adjust_prism_location_for_heredoc(node)
244
+
245
+ adjusted_value_location = Prism::Location.new(
246
+ node.value.location.send(:source),
247
+ node.value.location.start_offset,
248
+ adjusted_node_location.end_offset - node.value.location.start_offset,
243
249
  )
250
+
251
+ if type_variable_definition?(node.value)
252
+ TypeMember.new(
253
+ case node
254
+ when Prism::ConstantWriteNode
255
+ node.name.to_s
256
+ when Prism::ConstantPathWriteNode
257
+ node_string!(node.target)
258
+ end,
259
+ adjusted_value_location.slice,
260
+ loc: Loc.from_prism(@file, adjusted_node_location),
261
+ comments: node_comments(node),
262
+ )
263
+ else
264
+ Const.new(
265
+ case node
266
+ when Prism::ConstantWriteNode
267
+ node.name.to_s
268
+ when Prism::ConstantPathWriteNode
269
+ node_string!(node.target)
270
+ end,
271
+ adjusted_value_location.slice,
272
+ loc: Loc.from_prism(@file, adjusted_node_location),
273
+ comments: node_comments(node),
274
+ )
275
+ end
244
276
  end
245
277
  end
246
278
 
@@ -509,7 +541,7 @@ module RBI
509
541
  # Collect all the remaining comments after visiting the tree
510
542
  #: -> void
511
543
  def collect_orphan_comments
512
- last_line = T.let(nil, T.nilable(Integer))
544
+ last_line = nil #: Integer?
513
545
  last_node_end = @tree.nodes.last&.loc&.end_line
514
546
 
515
547
  @comments_by_line.each do |line, comment|
@@ -532,7 +564,7 @@ module RBI
532
564
 
533
565
  #: -> Tree
534
566
  def current_scope
535
- T.must(@scopes_stack.last) # Should never be nil since we create a Tree as the root
567
+ @scopes_stack.last #: as !nil # Should never be nil since we create a Tree as the root
536
568
  end
537
569
 
538
570
  #: -> Array[Sig]
@@ -544,7 +576,7 @@ module RBI
544
576
 
545
577
  #: (Array[Sig] sigs) -> Array[Comment]
546
578
  def detach_comments_from_sigs(sigs)
547
- comments = T.let([], T::Array[Comment])
579
+ comments = [] #: Array[Comment]
548
580
 
549
581
  sigs.each do |sig|
550
582
  comments += sig.comments.dup
@@ -576,7 +608,9 @@ module RBI
576
608
  def parse_comment(node)
577
609
  loc = Loc.from_prism(@file, node.location)
578
610
  string = node.location.slice
579
- if string.start_with?("#:")
611
+ # We also ignore RDoc directives such as `:nodoc:`
612
+ # See https://ruby.github.io/rdoc/RDoc/MarkupReference.html#class-RDoc::MarkupReference-label-Directives
613
+ if string.start_with?("#:") && !(string =~ /^#:[a-z_]+:/)
580
614
  RBSComment.new(string.gsub(/^#: ?/, "").rstrip, loc: loc)
581
615
  else
582
616
  Comment.new(string.gsub(/^# ?/, "").rstrip, loc: loc)
@@ -585,7 +619,7 @@ module RBI
585
619
 
586
620
  #: (Prism::Node? node) -> Array[Arg]
587
621
  def parse_send_args(node)
588
- args = T.let([], T::Array[Arg])
622
+ args = [] #: Array[Arg]
589
623
  return args unless node.is_a?(Prism::ArgumentsNode)
590
624
 
591
625
  node.arguments.each do |arg|
@@ -596,11 +630,13 @@ module RBI
596
630
 
597
631
  args << KwArg.new(
598
632
  node_string!(assoc.key).delete_suffix(":"),
599
- T.must(node_string(assoc.value)),
633
+ node_string(assoc.value), #: as !nil
600
634
  )
601
635
  end
602
636
  else
603
- args << Arg.new(T.must(node_string(arg)))
637
+ args << Arg.new(
638
+ node_string(arg), #: as !nil
639
+ )
604
640
  end
605
641
  end
606
642
 
@@ -701,7 +737,7 @@ module RBI
701
737
  return unless node_string(recv) =~ /(::)?Struct/
702
738
 
703
739
  members = []
704
- keyword_init = T.let(false, T::Boolean)
740
+ keyword_init = false #: bool
705
741
 
706
742
  args = send.arguments
707
743
  if args.is_a?(Prism::ArgumentsNode)
@@ -751,7 +787,7 @@ module RBI
751
787
  type = node_string!(type_arg)
752
788
  loc = node_loc(send)
753
789
  comments = node_comments(send)
754
- default_value = T.let(nil, T.nilable(String))
790
+ default_value = nil #: String?
755
791
 
756
792
  rest.each do |arg|
757
793
  next unless arg.is_a?(Prism::KeywordHashNode)
@@ -817,6 +853,19 @@ module RBI
817
853
  def type_variable_definition?(node)
818
854
  node.is_a?(Prism::CallNode) && (node.message == "type_member" || node.message == "type_template")
819
855
  end
856
+
857
+ #: (Prism::Node? node) -> bool
858
+ def t_enum_value?(node)
859
+ return false unless current_scope.is_a?(TEnumBlock)
860
+
861
+ return false unless node.is_a?(Prism::ConstantWriteNode)
862
+
863
+ value = node.value
864
+ return false unless value.is_a?(Prism::CallNode)
865
+ return false unless value.message == "new"
866
+
867
+ true
868
+ end
820
869
  end
821
870
 
822
871
  class SigBuilder < Visitor
@@ -827,7 +876,7 @@ module RBI
827
876
  def initialize(content, file:)
828
877
  super
829
878
 
830
- @current = T.let(Sig.new, Sig)
879
+ @current = Sig.new #: Sig
831
880
  end
832
881
 
833
882
  # @override
@@ -901,5 +950,57 @@ module RBI
901
950
  )
902
951
  end
903
952
  end
953
+
954
+ class HeredocLocationVisitor < Prism::Visitor
955
+ #: (Prism::Source source, Integer begin_offset, Integer end_offset) -> void
956
+ def initialize(source, begin_offset, end_offset)
957
+ super()
958
+ @source = source
959
+ @begin_offset = begin_offset
960
+ @end_offset = end_offset
961
+ @offset_last_newline = false #: bool
962
+ end
963
+
964
+ #: (Prism::StringNode node) -> void
965
+ def visit_string_node(node)
966
+ return unless node.heredoc?
967
+
968
+ closing_loc = node.closing_loc
969
+ return unless closing_loc
970
+
971
+ handle_string_node(node)
972
+ end
973
+
974
+ #: (Prism::InterpolatedStringNode node) -> void
975
+ def visit_interpolated_string_node(node)
976
+ return super unless node.heredoc?
977
+
978
+ closing_loc = node.closing_loc
979
+ return super unless closing_loc
980
+
981
+ handle_string_node(node)
982
+ end
983
+
984
+ #: -> Prism::Location
985
+ def location
986
+ Prism::Location.new(
987
+ @source,
988
+ @begin_offset,
989
+ @end_offset - @begin_offset - (@offset_last_newline ? 1 : 0),
990
+ )
991
+ end
992
+
993
+ private
994
+
995
+ #: (Prism::StringNode | Prism::InterpolatedStringNode node) -> void
996
+ def handle_string_node(node)
997
+ closing_loc = node.closing_loc #: as !nil
998
+
999
+ if closing_loc.end_offset > @end_offset
1000
+ @end_offset = closing_loc.end_offset
1001
+ @offset_last_newline = true if node.closing_loc&.slice&.end_with?("\n")
1002
+ end
1003
+ end
1004
+ end
904
1005
  end
905
1006
  end
data/lib/rbi/printer.rb CHANGED
@@ -23,8 +23,8 @@ module RBI
23
23
  @out = out
24
24
  @current_indent = indent
25
25
  @print_locs = print_locs
26
- @in_visibility_group = T.let(false, T::Boolean)
27
- @previous_node = T.let(nil, T.nilable(Node))
26
+ @in_visibility_group = false #: bool
27
+ @previous_node = nil #: Node?
28
28
  @max_line_length = max_line_length
29
29
  end
30
30
 
@@ -542,6 +542,16 @@ module RBI
542
542
  printl("end")
543
543
  end
544
544
 
545
+ # @override
546
+ #: (TEnumValue node) -> void
547
+ def visit_tenum_value(node)
548
+ print_blank_line_before(node)
549
+ print_loc(node)
550
+ visit_all(node.comments)
551
+
552
+ printl("#{node.name} = new")
553
+ end
554
+
545
555
  # @override
546
556
  #: (TypeMember node) -> void
547
557
  def visit_type_member(node)
@@ -675,6 +685,13 @@ module RBI
675
685
  node.comments.empty? && node.empty?
676
686
  when Attr
677
687
  node.comments.empty? && node.sigs.empty?
688
+ when Const
689
+ return false unless node.comments.empty?
690
+
691
+ loc = node.loc
692
+ return true unless loc
693
+
694
+ loc.begin_line == loc.end_line
678
695
  when Method
679
696
  node.comments.empty? && node.sigs.empty? && node.params.all? { |p| p.comments.empty? }
680
697
  when Sig
@@ -722,7 +739,9 @@ module RBI
722
739
  printn(" do")
723
740
  indent
724
741
  if modifiers.any?
725
- printl(T.must(modifiers.first))
742
+ printl(
743
+ modifiers.first, #: as !nil
744
+ )
726
745
  indent
727
746
  modifiers[1..]&.each do |modifier|
728
747
  printl(".#{modifier}")
@@ -771,7 +790,7 @@ module RBI
771
790
 
772
791
  #: (Sig node) -> Array[String]
773
792
  def sig_modifiers(node)
774
- modifiers = T.let([], T::Array[String])
793
+ modifiers = [] #: Array[String]
775
794
  modifiers << "abstract" if node.is_abstract
776
795
 
777
796
  if node.is_override
@@ -21,7 +21,7 @@ module RBI
21
21
  #: (Method) -> void
22
22
  def initialize(method)
23
23
  @method = method
24
- @result = T.let(Sig.new, Sig)
24
+ @result = Sig.new #: Sig
25
25
  end
26
26
 
27
27
  #: (::RBS::MethodType) -> void
@@ -44,7 +44,7 @@ module RBI
44
44
  raise Error, "No block param found" unless block_param
45
45
 
46
46
  block_name = block_param.name
47
- block_type = T.cast(translate_type(type.type), RBI::Type::Proc)
47
+ block_type = translate_type(type.type) #: as RBI::Type::Proc
48
48
 
49
49
  bind = type.self_type
50
50
  block_type.bind(translate_type(bind)) if bind
@@ -75,7 +75,7 @@ module RBI
75
75
  when ::RBS::Types::Optional
76
76
  Type.nilable(translate(type.type))
77
77
  when ::RBS::Types::Proc
78
- proc = T.cast(translate(type.type), Type::Proc)
78
+ proc = translate(type.type) #: as Type::Proc
79
79
  proc.bind(translate(type.self_type)) if type.self_type
80
80
  proc
81
81
  when ::RBS::Types::Record
@@ -23,9 +23,9 @@ module RBI
23
23
  @out = out
24
24
  @current_indent = indent
25
25
  @print_locs = print_locs
26
- @in_visibility_group = T.let(false, T::Boolean)
27
- @previous_node = T.let(nil, T.nilable(Node))
28
- @positional_names = T.let(positional_names, T::Boolean)
26
+ @in_visibility_group = false #: bool
27
+ @previous_node = nil #: Node?
28
+ @positional_names = positional_names #: bool
29
29
  end
30
30
 
31
31
  # Printing
@@ -349,7 +349,10 @@ module RBI
349
349
  print(": ")
350
350
  if sigs.any?
351
351
  first, *rest = sigs
352
- print_method_sig(node, T.must(first))
352
+ print_method_sig(
353
+ node,
354
+ first, #: as !nil
355
+ )
353
356
  if rest.any?
354
357
  spaces = node.name.size + 4
355
358
  rest.each do |sig|
@@ -645,19 +648,22 @@ module RBI
645
648
  # @override
646
649
  #: (TEnumBlock node) -> void
647
650
  def visit_tenum_block(node)
648
- node.nodes.each do |child|
649
- child = if child.is_a?(Const) && child.value == "new"
650
- parent = node.parent_scope
651
- Const.new(
652
- child.name,
653
- "T.let(nil, #{parent.is_a?(TEnum) ? parent.name : "T.untyped"})",
654
- comments: child.comments,
655
- )
656
- else
657
- child
658
- end
659
- visit(child)
660
- @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")
661
667
  end
662
668
  end
663
669
 
@@ -882,7 +888,7 @@ module RBI
882
888
 
883
889
  #: -> void
884
890
  def initialize
885
- @string = T.let(String.new, String)
891
+ @string = String.new #: String
886
892
  end
887
893
 
888
894
  #: (Type node) -> void
@@ -41,7 +41,8 @@ module RBI
41
41
 
42
42
  child.detach
43
43
  child.is_singleton = true
44
- T.must(node.parent_tree) << child
44
+ parent_tree = node.parent_tree #: as !nil
45
+ parent_tree << child
45
46
  end
46
47
 
47
48
  node.detach if node.nodes.empty?
@@ -29,7 +29,7 @@ module RBI
29
29
  def initialize
30
30
  super
31
31
 
32
- @current_visibility = T.let([Public.new], T::Array[Visibility])
32
+ @current_visibility = [Public.new] #: Array[Visibility]
33
33
  end
34
34
 
35
35
  # @override
@@ -46,7 +46,7 @@ module RBI
46
46
  visit_all(node.nodes.dup)
47
47
  @current_visibility.pop
48
48
  when Attr, Method
49
- node.visibility = T.must(@current_visibility.last)
49
+ node.visibility = @current_visibility.last #: as !nil
50
50
  end
51
51
  end
52
52
  end