rbi 0.0.15 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/rbi/formatter.rb +15 -9
- data/lib/rbi/index.rb +19 -5
- data/lib/rbi/loc.rb +3 -3
- data/lib/rbi/model.rb +52 -42
- data/lib/rbi/parser.rb +90 -48
- data/lib/rbi/printer.rb +5 -3
- data/lib/rbi/rewriters/add_sig_templates.rb +2 -2
- data/lib/rbi/rewriters/annotate.rb +2 -1
- data/lib/rbi/rewriters/deannotate.rb +1 -0
- data/lib/rbi/rewriters/merge_trees.rb +23 -12
- data/lib/rbi/rewriters/nest_non_public_methods.rb +1 -0
- data/lib/rbi/rewriters/nest_singleton_methods.rb +1 -0
- data/lib/rbi/rewriters/remove_known_definitions.rb +16 -12
- data/lib/rbi/rewriters/sort_nodes.rb +24 -10
- data/lib/rbi/version.rb +1 -1
- data/lib/rbi.rb +0 -5
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b377a351b9385e3c256fa079584f193232a767df408850e72265db4319346aa9
|
4
|
+
data.tar.gz: 04a3e0cd339374e9ccc3f0d2d769e564730ad69881c73c4f42ae328db48bcad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9123353786e09d5869e8621f086ef057d57b21ff8a05ddb6c1be3dffa5dc0d94bc433e0074f0e7b4dff0eb63ed66d300ab11856d536a299f8560ec53912f444
|
7
|
+
data.tar.gz: 6a12ef064826678ce3a47b6a1d327e8de0b506fd09c100f4f88111afe6b84d11549cf41ef727a70bb9b93e16dd1868a00f3ed7a3e5b9e10578e159a7aafa2c04
|
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.0")
|
13
|
-
gem("rubocop", "~> 1.
|
13
|
+
gem("rubocop", "~> 1.54", 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
@@ -5,8 +5,20 @@ module RBI
|
|
5
5
|
class Formatter
|
6
6
|
extend T::Sig
|
7
7
|
|
8
|
-
sig { returns(T::Boolean) }
|
9
|
-
|
8
|
+
sig { params(sort_nodes: T::Boolean).returns(T::Boolean) }
|
9
|
+
attr_writer :sort_nodes
|
10
|
+
|
11
|
+
sig { params(nest_singleton_methods: T::Boolean).returns(T::Boolean) }
|
12
|
+
attr_writer :nest_singleton_methods
|
13
|
+
|
14
|
+
sig { params(add_sig_templates: T::Boolean).returns(T::Boolean) }
|
15
|
+
attr_writer :add_sig_templates
|
16
|
+
|
17
|
+
sig { params(group_nodes: T::Boolean).returns(T::Boolean) }
|
18
|
+
attr_writer :group_nodes
|
19
|
+
|
20
|
+
sig { params(nest_non_public_methods: T::Boolean).returns(T::Boolean) }
|
21
|
+
attr_writer :nest_non_public_methods
|
10
22
|
|
11
23
|
sig { returns(T.nilable(Integer)) }
|
12
24
|
attr_accessor :max_line_length
|
@@ -18,7 +30,7 @@ module RBI
|
|
18
30
|
max_line_length: T.nilable(Integer),
|
19
31
|
nest_singleton_methods: T::Boolean,
|
20
32
|
nest_non_public_methods: T::Boolean,
|
21
|
-
sort_nodes: T::Boolean
|
33
|
+
sort_nodes: T::Boolean,
|
22
34
|
).void
|
23
35
|
end
|
24
36
|
def initialize(
|
@@ -43,12 +55,6 @@ module RBI
|
|
43
55
|
file.string(max_line_length: @max_line_length)
|
44
56
|
end
|
45
57
|
|
46
|
-
sig { params(tree: RBI::Tree).returns(String) }
|
47
|
-
def print_tree(tree)
|
48
|
-
format_tree(tree)
|
49
|
-
tree.string(max_line_length: @max_line_length)
|
50
|
-
end
|
51
|
-
|
52
58
|
sig { params(file: RBI::File).void }
|
53
59
|
def format_file(file)
|
54
60
|
format_tree(file.root)
|
data/lib/rbi/index.rb
CHANGED
@@ -6,11 +6,15 @@ module RBI
|
|
6
6
|
extend T::Sig
|
7
7
|
include T::Enumerable
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
index
|
9
|
+
class << self
|
10
|
+
extend T::Sig
|
11
|
+
|
12
|
+
sig { params(node: Node).returns(Index) }
|
13
|
+
def index(*node)
|
14
|
+
index = Index.new
|
15
|
+
index.visit_all(node)
|
16
|
+
index
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
sig { void }
|
@@ -171,6 +175,16 @@ module RBI
|
|
171
175
|
end
|
172
176
|
end
|
173
177
|
|
178
|
+
class TypeMember
|
179
|
+
extend T::Sig
|
180
|
+
include Indexable
|
181
|
+
|
182
|
+
sig { override.returns(T::Array[String]) }
|
183
|
+
def index_ids
|
184
|
+
[to_s]
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
174
188
|
class Send
|
175
189
|
extend T::Sig
|
176
190
|
include Indexable
|
data/lib/rbi/loc.rb
CHANGED
@@ -17,7 +17,7 @@ module RBI
|
|
17
17
|
begin_line: T.nilable(Integer),
|
18
18
|
end_line: T.nilable(Integer),
|
19
19
|
begin_column: T.nilable(Integer),
|
20
|
-
end_column: T.nilable(Integer)
|
20
|
+
end_column: T.nilable(Integer),
|
21
21
|
).void
|
22
22
|
end
|
23
23
|
def initialize(file: nil, begin_line: nil, end_line: nil, begin_column: nil, end_column: nil)
|
@@ -36,8 +36,8 @@ module RBI
|
|
36
36
|
sig { returns(T.nilable(String)) }
|
37
37
|
def source
|
38
38
|
file = self.file
|
39
|
-
return
|
40
|
-
return
|
39
|
+
return unless file
|
40
|
+
return unless ::File.file?(file)
|
41
41
|
|
42
42
|
return ::File.read(file) unless begin_line && end_line
|
43
43
|
|
data/lib/rbi/model.rb
CHANGED
@@ -24,6 +24,7 @@ module RBI
|
|
24
24
|
def detach
|
25
25
|
tree = parent_tree
|
26
26
|
return unless tree
|
27
|
+
|
27
28
|
tree.nodes.delete(self)
|
28
29
|
self.parent_tree = nil
|
29
30
|
end
|
@@ -32,8 +33,10 @@ module RBI
|
|
32
33
|
def replace(node)
|
33
34
|
tree = parent_tree
|
34
35
|
raise unless tree
|
36
|
+
|
35
37
|
index = tree.nodes.index(self)
|
36
38
|
raise unless index
|
39
|
+
|
37
40
|
tree.nodes[index] = node
|
38
41
|
node.parent_tree = tree
|
39
42
|
self.parent_tree = nil
|
@@ -62,6 +65,7 @@ module RBI
|
|
62
65
|
sig { params(other: Object).returns(T::Boolean) }
|
63
66
|
def ==(other)
|
64
67
|
return false unless other.is_a?(Comment)
|
68
|
+
|
65
69
|
text == other.text
|
66
70
|
end
|
67
71
|
end
|
@@ -109,7 +113,7 @@ module RBI
|
|
109
113
|
params(
|
110
114
|
loc: T.nilable(Loc),
|
111
115
|
comments: T::Array[Comment],
|
112
|
-
block: T.nilable(T.proc.params(node: Tree).void)
|
116
|
+
block: T.nilable(T.proc.params(node: Tree).void),
|
113
117
|
).void
|
114
118
|
end
|
115
119
|
def initialize(loc: nil, comments: [], &block)
|
@@ -146,7 +150,7 @@ module RBI
|
|
146
150
|
params(
|
147
151
|
strictness: T.nilable(String),
|
148
152
|
comments: T::Array[Comment],
|
149
|
-
block: T.nilable(T.proc.params(file: File).void)
|
153
|
+
block: T.nilable(T.proc.params(file: File).void),
|
150
154
|
).void
|
151
155
|
end
|
152
156
|
def initialize(strictness: nil, comments: [], &block)
|
@@ -194,7 +198,7 @@ module RBI
|
|
194
198
|
name: String,
|
195
199
|
loc: T.nilable(Loc),
|
196
200
|
comments: T::Array[Comment],
|
197
|
-
block: T.nilable(T.proc.params(node: Module).void)
|
201
|
+
block: T.nilable(T.proc.params(node: Module).void),
|
198
202
|
).void
|
199
203
|
end
|
200
204
|
def initialize(name, loc: nil, comments: [], &block)
|
@@ -206,6 +210,7 @@ module RBI
|
|
206
210
|
sig { override.returns(String) }
|
207
211
|
def fully_qualified_name
|
208
212
|
return name if name.start_with?("::")
|
213
|
+
|
209
214
|
"#{parent_scope&.fully_qualified_name}::#{name}"
|
210
215
|
end
|
211
216
|
end
|
@@ -225,7 +230,7 @@ module RBI
|
|
225
230
|
superclass_name: T.nilable(String),
|
226
231
|
loc: T.nilable(Loc),
|
227
232
|
comments: T::Array[Comment],
|
228
|
-
block: T.nilable(T.proc.params(node: Class).void)
|
233
|
+
block: T.nilable(T.proc.params(node: Class).void),
|
229
234
|
).void
|
230
235
|
end
|
231
236
|
def initialize(name, superclass_name: nil, loc: nil, comments: [], &block)
|
@@ -238,6 +243,7 @@ module RBI
|
|
238
243
|
sig { override.returns(String) }
|
239
244
|
def fully_qualified_name
|
240
245
|
return name if name.start_with?("::")
|
246
|
+
|
241
247
|
"#{parent_scope&.fully_qualified_name}::#{name}"
|
242
248
|
end
|
243
249
|
end
|
@@ -249,7 +255,7 @@ module RBI
|
|
249
255
|
params(
|
250
256
|
loc: T.nilable(Loc),
|
251
257
|
comments: T::Array[Comment],
|
252
|
-
block: T.nilable(T.proc.params(node: SingletonClass).void)
|
258
|
+
block: T.nilable(T.proc.params(node: SingletonClass).void),
|
253
259
|
).void
|
254
260
|
end
|
255
261
|
def initialize(loc: nil, comments: [], &block)
|
@@ -282,7 +288,7 @@ module RBI
|
|
282
288
|
keyword_init: T::Boolean,
|
283
289
|
loc: T.nilable(Loc),
|
284
290
|
comments: T::Array[Comment],
|
285
|
-
block: T.nilable(T.proc.params(struct: Struct).void)
|
291
|
+
block: T.nilable(T.proc.params(struct: Struct).void),
|
286
292
|
).void
|
287
293
|
end
|
288
294
|
def initialize(name, members: [], keyword_init: false, loc: nil, comments: [], &block)
|
@@ -296,6 +302,7 @@ module RBI
|
|
296
302
|
sig { override.returns(String) }
|
297
303
|
def fully_qualified_name
|
298
304
|
return name if name.start_with?("::")
|
305
|
+
|
299
306
|
"#{parent_scope&.fully_qualified_name}::#{name}"
|
300
307
|
end
|
301
308
|
end
|
@@ -314,7 +321,7 @@ module RBI
|
|
314
321
|
value: String,
|
315
322
|
loc: T.nilable(Loc),
|
316
323
|
comments: T::Array[Comment],
|
317
|
-
block: T.nilable(T.proc.params(node: Const).void)
|
324
|
+
block: T.nilable(T.proc.params(node: Const).void),
|
318
325
|
).void
|
319
326
|
end
|
320
327
|
def initialize(name, value, loc: nil, comments: [], &block)
|
@@ -327,6 +334,7 @@ module RBI
|
|
327
334
|
sig { returns(String) }
|
328
335
|
def fully_qualified_name
|
329
336
|
return name if name.start_with?("::")
|
337
|
+
|
330
338
|
"#{parent_scope&.fully_qualified_name}::#{name}"
|
331
339
|
end
|
332
340
|
|
@@ -360,7 +368,7 @@ module RBI
|
|
360
368
|
visibility: Visibility,
|
361
369
|
sigs: T::Array[Sig],
|
362
370
|
loc: T.nilable(Loc),
|
363
|
-
comments: T::Array[Comment]
|
371
|
+
comments: T::Array[Comment],
|
364
372
|
).void
|
365
373
|
end
|
366
374
|
def initialize(name, names, visibility: Public.new, sigs: [], loc: nil, comments: [])
|
@@ -385,7 +393,7 @@ module RBI
|
|
385
393
|
sigs: T::Array[Sig],
|
386
394
|
loc: T.nilable(Loc),
|
387
395
|
comments: T::Array[Comment],
|
388
|
-
block: T.nilable(T.proc.params(node: AttrAccessor).void)
|
396
|
+
block: T.nilable(T.proc.params(node: AttrAccessor).void),
|
389
397
|
).void
|
390
398
|
end
|
391
399
|
def initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block)
|
@@ -417,7 +425,7 @@ module RBI
|
|
417
425
|
sigs: T::Array[Sig],
|
418
426
|
loc: T.nilable(Loc),
|
419
427
|
comments: T::Array[Comment],
|
420
|
-
block: T.nilable(T.proc.params(node: AttrReader).void)
|
428
|
+
block: T.nilable(T.proc.params(node: AttrReader).void),
|
421
429
|
).void
|
422
430
|
end
|
423
431
|
def initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block)
|
@@ -449,7 +457,7 @@ module RBI
|
|
449
457
|
sigs: T::Array[Sig],
|
450
458
|
loc: T.nilable(Loc),
|
451
459
|
comments: T::Array[Comment],
|
452
|
-
block: T.nilable(T.proc.params(node: AttrWriter).void)
|
460
|
+
block: T.nilable(T.proc.params(node: AttrWriter).void),
|
453
461
|
).void
|
454
462
|
end
|
455
463
|
def initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block)
|
@@ -499,7 +507,7 @@ module RBI
|
|
499
507
|
sigs: T::Array[Sig],
|
500
508
|
loc: T.nilable(Loc),
|
501
509
|
comments: T::Array[Comment],
|
502
|
-
block: T.nilable(T.proc.params(node: Method).void)
|
510
|
+
block: T.nilable(T.proc.params(node: Method).void),
|
503
511
|
).void
|
504
512
|
end
|
505
513
|
def initialize(
|
@@ -576,7 +584,7 @@ module RBI
|
|
576
584
|
name: String,
|
577
585
|
loc: T.nilable(Loc),
|
578
586
|
comments: T::Array[Comment],
|
579
|
-
block: T.nilable(T.proc.params(node: ReqParam).void)
|
587
|
+
block: T.nilable(T.proc.params(node: ReqParam).void),
|
580
588
|
).void
|
581
589
|
end
|
582
590
|
def initialize(name, loc: nil, comments: [], &block)
|
@@ -602,7 +610,7 @@ module RBI
|
|
602
610
|
value: String,
|
603
611
|
loc: T.nilable(Loc),
|
604
612
|
comments: T::Array[Comment],
|
605
|
-
block: T.nilable(T.proc.params(node: OptParam).void)
|
613
|
+
block: T.nilable(T.proc.params(node: OptParam).void),
|
606
614
|
).void
|
607
615
|
end
|
608
616
|
def initialize(name, value, loc: nil, comments: [], &block)
|
@@ -613,7 +621,7 @@ module RBI
|
|
613
621
|
|
614
622
|
sig { params(other: T.nilable(Object)).returns(T::Boolean) }
|
615
623
|
def ==(other)
|
616
|
-
OptParam === other && name == other.name
|
624
|
+
OptParam === other && name == other.name
|
617
625
|
end
|
618
626
|
end
|
619
627
|
|
@@ -625,7 +633,7 @@ module RBI
|
|
625
633
|
name: String,
|
626
634
|
loc: T.nilable(Loc),
|
627
635
|
comments: T::Array[Comment],
|
628
|
-
block: T.nilable(T.proc.params(node: RestParam).void)
|
636
|
+
block: T.nilable(T.proc.params(node: RestParam).void),
|
629
637
|
).void
|
630
638
|
end
|
631
639
|
def initialize(name, loc: nil, comments: [], &block)
|
@@ -652,7 +660,7 @@ module RBI
|
|
652
660
|
name: String,
|
653
661
|
loc: T.nilable(Loc),
|
654
662
|
comments: T::Array[Comment],
|
655
|
-
block: T.nilable(T.proc.params(node: KwParam).void)
|
663
|
+
block: T.nilable(T.proc.params(node: KwParam).void),
|
656
664
|
).void
|
657
665
|
end
|
658
666
|
def initialize(name, loc: nil, comments: [], &block)
|
@@ -683,7 +691,7 @@ module RBI
|
|
683
691
|
value: String,
|
684
692
|
loc: T.nilable(Loc),
|
685
693
|
comments: T::Array[Comment],
|
686
|
-
block: T.nilable(T.proc.params(node: KwOptParam).void)
|
694
|
+
block: T.nilable(T.proc.params(node: KwOptParam).void),
|
687
695
|
).void
|
688
696
|
end
|
689
697
|
def initialize(name, value, loc: nil, comments: [], &block)
|
@@ -699,7 +707,7 @@ module RBI
|
|
699
707
|
|
700
708
|
sig { params(other: T.nilable(Object)).returns(T::Boolean) }
|
701
709
|
def ==(other)
|
702
|
-
KwOptParam === other && name == other.name
|
710
|
+
KwOptParam === other && name == other.name
|
703
711
|
end
|
704
712
|
end
|
705
713
|
|
@@ -711,7 +719,7 @@ module RBI
|
|
711
719
|
name: String,
|
712
720
|
loc: T.nilable(Loc),
|
713
721
|
comments: T::Array[Comment],
|
714
|
-
block: T.nilable(T.proc.params(node: KwRestParam).void)
|
722
|
+
block: T.nilable(T.proc.params(node: KwRestParam).void),
|
715
723
|
).void
|
716
724
|
end
|
717
725
|
def initialize(name, loc: nil, comments: [], &block)
|
@@ -738,7 +746,7 @@ module RBI
|
|
738
746
|
name: String,
|
739
747
|
loc: T.nilable(Loc),
|
740
748
|
comments: T::Array[Comment],
|
741
|
-
block: T.nilable(T.proc.params(node: BlockParam).void)
|
749
|
+
block: T.nilable(T.proc.params(node: BlockParam).void),
|
742
750
|
).void
|
743
751
|
end
|
744
752
|
def initialize(name, loc: nil, comments: [], &block)
|
@@ -773,7 +781,7 @@ module RBI
|
|
773
781
|
name: String,
|
774
782
|
names: T::Array[String],
|
775
783
|
loc: T.nilable(Loc),
|
776
|
-
comments: T::Array[Comment]
|
784
|
+
comments: T::Array[Comment],
|
777
785
|
).void
|
778
786
|
end
|
779
787
|
def initialize(name, names, loc: nil, comments: [])
|
@@ -791,7 +799,7 @@ module RBI
|
|
791
799
|
names: String,
|
792
800
|
loc: T.nilable(Loc),
|
793
801
|
comments: T::Array[Comment],
|
794
|
-
block: T.nilable(T.proc.params(node: Include).void)
|
802
|
+
block: T.nilable(T.proc.params(node: Include).void),
|
795
803
|
).void
|
796
804
|
end
|
797
805
|
def initialize(name, *names, loc: nil, comments: [], &block)
|
@@ -814,7 +822,7 @@ module RBI
|
|
814
822
|
names: String,
|
815
823
|
loc: T.nilable(Loc),
|
816
824
|
comments: T::Array[Comment],
|
817
|
-
block: T.nilable(T.proc.params(node: Extend).void)
|
825
|
+
block: T.nilable(T.proc.params(node: Extend).void),
|
818
826
|
).void
|
819
827
|
end
|
820
828
|
def initialize(name, *names, loc: nil, comments: [], &block)
|
@@ -873,7 +881,7 @@ module RBI
|
|
873
881
|
params(
|
874
882
|
loc: T.nilable(Loc),
|
875
883
|
comments: T::Array[Comment],
|
876
|
-
block: T.nilable(T.proc.params(node: Public).void)
|
884
|
+
block: T.nilable(T.proc.params(node: Public).void),
|
877
885
|
).void
|
878
886
|
end
|
879
887
|
def initialize(loc: nil, comments: [], &block)
|
@@ -889,7 +897,7 @@ module RBI
|
|
889
897
|
params(
|
890
898
|
loc: T.nilable(Loc),
|
891
899
|
comments: T::Array[Comment],
|
892
|
-
block: T.nilable(T.proc.params(node: Protected).void)
|
900
|
+
block: T.nilable(T.proc.params(node: Protected).void),
|
893
901
|
).void
|
894
902
|
end
|
895
903
|
def initialize(loc: nil, comments: [], &block)
|
@@ -905,7 +913,7 @@ module RBI
|
|
905
913
|
params(
|
906
914
|
loc: T.nilable(Loc),
|
907
915
|
comments: T::Array[Comment],
|
908
|
-
block: T.nilable(T.proc.params(node: Private).void)
|
916
|
+
block: T.nilable(T.proc.params(node: Private).void),
|
909
917
|
).void
|
910
918
|
end
|
911
919
|
def initialize(loc: nil, comments: [], &block)
|
@@ -931,7 +939,7 @@ module RBI
|
|
931
939
|
args: T::Array[Arg],
|
932
940
|
loc: T.nilable(Loc),
|
933
941
|
comments: T::Array[Comment],
|
934
|
-
block: T.nilable(T.proc.params(node: Send).void)
|
942
|
+
block: T.nilable(T.proc.params(node: Send).void),
|
935
943
|
).void
|
936
944
|
end
|
937
945
|
def initialize(method, args = [], loc: nil, comments: [], &block)
|
@@ -966,7 +974,7 @@ module RBI
|
|
966
974
|
sig do
|
967
975
|
params(
|
968
976
|
value: String,
|
969
|
-
loc: T.nilable(Loc)
|
977
|
+
loc: T.nilable(Loc),
|
970
978
|
).void
|
971
979
|
end
|
972
980
|
def initialize(value, loc: nil)
|
@@ -995,7 +1003,7 @@ module RBI
|
|
995
1003
|
params(
|
996
1004
|
keyword: String,
|
997
1005
|
value: String,
|
998
|
-
loc: T.nilable(Loc)
|
1006
|
+
loc: T.nilable(Loc),
|
999
1007
|
).void
|
1000
1008
|
end
|
1001
1009
|
def initialize(keyword, value, loc: nil)
|
@@ -1045,7 +1053,7 @@ module RBI
|
|
1045
1053
|
type_params: T::Array[String],
|
1046
1054
|
checked: T.nilable(Symbol),
|
1047
1055
|
loc: T.nilable(Loc),
|
1048
|
-
block: T.nilable(T.proc.params(node: Sig).void)
|
1056
|
+
block: T.nilable(T.proc.params(node: Sig).void),
|
1049
1057
|
).void
|
1050
1058
|
end
|
1051
1059
|
def initialize(
|
@@ -1080,6 +1088,7 @@ module RBI
|
|
1080
1088
|
sig { params(other: Object).returns(T::Boolean) }
|
1081
1089
|
def ==(other)
|
1082
1090
|
return false unless other.is_a?(Sig)
|
1091
|
+
|
1083
1092
|
params == other.params && return_type == other.return_type && is_abstract == other.is_abstract &&
|
1084
1093
|
is_override == other.is_override && is_overridable == other.is_overridable && is_final == other.is_final &&
|
1085
1094
|
type_params == other.type_params && checked == other.checked
|
@@ -1098,7 +1107,7 @@ module RBI
|
|
1098
1107
|
type: String,
|
1099
1108
|
loc: T.nilable(Loc),
|
1100
1109
|
comments: T::Array[Comment],
|
1101
|
-
block: T.nilable(T.proc.params(node: SigParam).void)
|
1110
|
+
block: T.nilable(T.proc.params(node: SigParam).void),
|
1102
1111
|
).void
|
1103
1112
|
end
|
1104
1113
|
def initialize(name, type, loc: nil, comments: [], &block)
|
@@ -1124,7 +1133,7 @@ module RBI
|
|
1124
1133
|
name: String,
|
1125
1134
|
loc: T.nilable(Loc),
|
1126
1135
|
comments: T::Array[Comment],
|
1127
|
-
block: T.nilable(T.proc.params(klass: TStruct).void)
|
1136
|
+
block: T.nilable(T.proc.params(klass: TStruct).void),
|
1128
1137
|
).void
|
1129
1138
|
end
|
1130
1139
|
def initialize(name, loc: nil, comments: [], &block)
|
@@ -1151,7 +1160,7 @@ module RBI
|
|
1151
1160
|
type: String,
|
1152
1161
|
default: T.nilable(String),
|
1153
1162
|
loc: T.nilable(Loc),
|
1154
|
-
comments: T::Array[Comment]
|
1163
|
+
comments: T::Array[Comment],
|
1155
1164
|
).void
|
1156
1165
|
end
|
1157
1166
|
def initialize(name, type, default: nil, loc: nil, comments: [])
|
@@ -1175,7 +1184,7 @@ module RBI
|
|
1175
1184
|
default: T.nilable(String),
|
1176
1185
|
loc: T.nilable(Loc),
|
1177
1186
|
comments: T::Array[Comment],
|
1178
|
-
block: T.nilable(T.proc.params(node: TStructConst).void)
|
1187
|
+
block: T.nilable(T.proc.params(node: TStructConst).void),
|
1179
1188
|
).void
|
1180
1189
|
end
|
1181
1190
|
def initialize(name, type, default: nil, loc: nil, comments: [], &block)
|
@@ -1205,7 +1214,7 @@ module RBI
|
|
1205
1214
|
default: T.nilable(String),
|
1206
1215
|
loc: T.nilable(Loc),
|
1207
1216
|
comments: T::Array[Comment],
|
1208
|
-
block: T.nilable(T.proc.params(node: TStructProp).void)
|
1217
|
+
block: T.nilable(T.proc.params(node: TStructProp).void),
|
1209
1218
|
).void
|
1210
1219
|
end
|
1211
1220
|
def initialize(name, type, default: nil, loc: nil, comments: [], &block)
|
@@ -1235,7 +1244,7 @@ module RBI
|
|
1235
1244
|
name: String,
|
1236
1245
|
loc: T.nilable(Loc),
|
1237
1246
|
comments: T::Array[Comment],
|
1238
|
-
block: T.nilable(T.proc.params(klass: TEnum).void)
|
1247
|
+
block: T.nilable(T.proc.params(klass: TEnum).void),
|
1239
1248
|
).void
|
1240
1249
|
end
|
1241
1250
|
def initialize(name, loc: nil, comments: [], &block)
|
@@ -1255,7 +1264,7 @@ module RBI
|
|
1255
1264
|
names: T::Array[String],
|
1256
1265
|
loc: T.nilable(Loc),
|
1257
1266
|
comments: T::Array[Comment],
|
1258
|
-
block: T.nilable(T.proc.params(node: TEnumBlock).void)
|
1267
|
+
block: T.nilable(T.proc.params(node: TEnumBlock).void),
|
1259
1268
|
).void
|
1260
1269
|
end
|
1261
1270
|
def initialize(names = [], loc: nil, comments: [], &block)
|
@@ -1293,7 +1302,7 @@ module RBI
|
|
1293
1302
|
name: String,
|
1294
1303
|
loc: T.nilable(Loc),
|
1295
1304
|
comments: T::Array[Comment],
|
1296
|
-
block: T.nilable(T.proc.params(node: Helper).void)
|
1305
|
+
block: T.nilable(T.proc.params(node: Helper).void),
|
1297
1306
|
).void
|
1298
1307
|
end
|
1299
1308
|
def initialize(name, loc: nil, comments: [], &block)
|
@@ -1320,7 +1329,7 @@ module RBI
|
|
1320
1329
|
value: String,
|
1321
1330
|
loc: T.nilable(Loc),
|
1322
1331
|
comments: T::Array[Comment],
|
1323
|
-
block: T.nilable(T.proc.params(node: TypeMember).void)
|
1332
|
+
block: T.nilable(T.proc.params(node: TypeMember).void),
|
1324
1333
|
).void
|
1325
1334
|
end
|
1326
1335
|
def initialize(name, value, loc: nil, comments: [], &block)
|
@@ -1333,6 +1342,7 @@ module RBI
|
|
1333
1342
|
sig { returns(String) }
|
1334
1343
|
def fully_qualified_name
|
1335
1344
|
return name if name.start_with?("::")
|
1345
|
+
|
1336
1346
|
"#{parent_scope&.fully_qualified_name}::#{name}"
|
1337
1347
|
end
|
1338
1348
|
|
@@ -1351,7 +1361,7 @@ module RBI
|
|
1351
1361
|
names: String,
|
1352
1362
|
loc: T.nilable(Loc),
|
1353
1363
|
comments: T::Array[Comment],
|
1354
|
-
block: T.nilable(T.proc.params(node: MixesInClassMethods).void)
|
1364
|
+
block: T.nilable(T.proc.params(node: MixesInClassMethods).void),
|
1355
1365
|
).void
|
1356
1366
|
end
|
1357
1367
|
def initialize(name, *names, loc: nil, comments: [], &block)
|
@@ -1375,7 +1385,7 @@ module RBI
|
|
1375
1385
|
params(
|
1376
1386
|
name: String,
|
1377
1387
|
loc: T.nilable(Loc),
|
1378
|
-
comments: T::Array[Comment]
|
1388
|
+
comments: T::Array[Comment],
|
1379
1389
|
).void
|
1380
1390
|
end
|
1381
1391
|
def initialize(name, loc: nil, comments: [])
|
data/lib/rbi/parser.rb
CHANGED
@@ -66,20 +66,30 @@ module RBI
|
|
66
66
|
require "unparser" unless defined?(::Unparser)
|
67
67
|
end
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
Parser.new.parse_string(string)
|
72
|
-
end
|
69
|
+
class << self
|
70
|
+
extend T::Sig
|
73
71
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
sig { params(string: String).returns(Tree) }
|
73
|
+
def parse_string(string)
|
74
|
+
Parser.new.parse_string(string)
|
75
|
+
end
|
76
|
+
|
77
|
+
sig { params(path: String).returns(Tree) }
|
78
|
+
def parse_file(path)
|
79
|
+
Parser.new.parse_file(path)
|
80
|
+
end
|
81
|
+
|
82
|
+
sig { params(paths: T::Array[String]).returns(T::Array[Tree]) }
|
83
|
+
def parse_files(paths)
|
84
|
+
parser = Parser.new
|
85
|
+
paths.map { |path| parser.parse_file(path) }
|
86
|
+
end
|
78
87
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
88
|
+
sig { params(strings: T::Array[String]).returns(T::Array[Tree]) }
|
89
|
+
def parse_strings(strings)
|
90
|
+
parser = Parser.new
|
91
|
+
strings.map { |string| parser.parse_string(string) }
|
92
|
+
end
|
83
93
|
end
|
84
94
|
|
85
95
|
sig { params(string: String).returns(Tree) }
|
@@ -87,12 +97,6 @@ module RBI
|
|
87
97
|
parse(string, file: "-")
|
88
98
|
end
|
89
99
|
|
90
|
-
sig { params(strings: T::Array[String]).returns(T::Array[Tree]) }
|
91
|
-
def self.parse_strings(strings)
|
92
|
-
parser = Parser.new
|
93
|
-
strings.map { |string| parser.parse_string(string) }
|
94
|
-
end
|
95
|
-
|
96
100
|
sig { params(path: String).returns(Tree) }
|
97
101
|
def parse_file(path)
|
98
102
|
parse(::File.read(path), file: path)
|
@@ -166,7 +170,7 @@ module RBI
|
|
166
170
|
params(
|
167
171
|
file: String,
|
168
172
|
comments: T::Array[::Parser::Source::Comment],
|
169
|
-
nodes_comments_assoc: T::Hash[::Parser::Source::Map, T::Array[::Parser::Source::Comment]]
|
173
|
+
nodes_comments_assoc: T::Hash[::Parser::Source::Map, T::Array[::Parser::Source::Comment]],
|
170
174
|
).void
|
171
175
|
end
|
172
176
|
def initialize(file:, comments: [], nodes_comments_assoc: {})
|
@@ -192,6 +196,7 @@ module RBI
|
|
192
196
|
sig { override.params(node: T.nilable(Object)).void }
|
193
197
|
def visit(node)
|
194
198
|
return unless node.is_a?(AST::Node)
|
199
|
+
|
195
200
|
@last_node = node
|
196
201
|
|
197
202
|
case node.type
|
@@ -250,6 +255,8 @@ module RBI
|
|
250
255
|
node_value = node.children[2]
|
251
256
|
if struct_definition?(node_value)
|
252
257
|
parse_struct(node)
|
258
|
+
elsif type_variable_definition?(node_value)
|
259
|
+
parse_type_variable(node)
|
253
260
|
else
|
254
261
|
name = parse_name(node)
|
255
262
|
value = parse_expr(node_value)
|
@@ -270,7 +277,7 @@ module RBI
|
|
270
277
|
params: node.children[1].children.map { |child| parse_param(child) },
|
271
278
|
sigs: current_sigs,
|
272
279
|
loc: loc,
|
273
|
-
comments: current_sigs_comments + node_comments(node)
|
280
|
+
comments: current_sigs_comments + node_comments(node),
|
274
281
|
)
|
275
282
|
when :defs
|
276
283
|
Method.new(
|
@@ -279,7 +286,7 @@ module RBI
|
|
279
286
|
is_singleton: true,
|
280
287
|
sigs: current_sigs,
|
281
288
|
loc: loc,
|
282
|
-
comments: current_sigs_comments + node_comments(node)
|
289
|
+
comments: current_sigs_comments + node_comments(node),
|
283
290
|
)
|
284
291
|
else
|
285
292
|
raise ParseError.new("Unsupported def node type `#{node.type}`", loc)
|
@@ -317,7 +324,7 @@ module RBI
|
|
317
324
|
sig { params(node: AST::Node).returns(T.nilable(RBI::Node)) }
|
318
325
|
def parse_send(node)
|
319
326
|
recv = node.children[0]
|
320
|
-
return
|
327
|
+
return if recv && recv != :self
|
321
328
|
|
322
329
|
method_name = node.children[1]
|
323
330
|
loc = node_loc(node)
|
@@ -362,6 +369,7 @@ module RBI
|
|
362
369
|
when :send
|
363
370
|
snode = parse_send(nested_node)
|
364
371
|
raise ParseError.new("Unexpected token `private` before `#{nested_node.type}`", loc) unless snode.is_a?(Attr)
|
372
|
+
|
365
373
|
snode.visibility = visibility
|
366
374
|
snode
|
367
375
|
when nil
|
@@ -459,6 +467,24 @@ module RBI
|
|
459
467
|
struct
|
460
468
|
end
|
461
469
|
|
470
|
+
sig { params(node: AST::Node).returns(T::Boolean) }
|
471
|
+
def type_variable_definition?(node)
|
472
|
+
(node.type == :send && node.children[0].nil? && (node.children[1] == :type_member ||
|
473
|
+
node.children[1] == :type_template)) ||
|
474
|
+
(node.type == :block && type_variable_definition?(node.children[0]))
|
475
|
+
end
|
476
|
+
|
477
|
+
sig { params(node: AST::Node).returns(RBI::TypeMember) }
|
478
|
+
def parse_type_variable(node)
|
479
|
+
name = parse_name(node)
|
480
|
+
loc = node_loc(node)
|
481
|
+
comments = node_comments(node)
|
482
|
+
|
483
|
+
send = node.children[2]
|
484
|
+
|
485
|
+
TypeMember.new(name, send.location.expression.source, loc: loc, comments: comments)
|
486
|
+
end
|
487
|
+
|
462
488
|
sig { params(node: AST::Node).returns([String, String, T.nilable(String)]) }
|
463
489
|
def parse_tstruct_prop(node)
|
464
490
|
name = node.children[2].children[0].to_s
|
@@ -516,6 +542,7 @@ module RBI
|
|
516
542
|
def node_comments(node)
|
517
543
|
comments = @nodes_comments_assoc[node.location]
|
518
544
|
return [] unless comments
|
545
|
+
|
519
546
|
comments.map do |comment|
|
520
547
|
text = comment.text[1..-1].strip
|
521
548
|
loc = Loc.from_ast_loc(@file, comment.location)
|
@@ -592,7 +619,7 @@ module RBI
|
|
592
619
|
begin_line: first_loc&.begin_line || 0,
|
593
620
|
begin_column: first_loc&.begin_column || 0,
|
594
621
|
end_line: last_loc&.end_line || 0,
|
595
|
-
end_column: last_loc&.end_column || 0
|
622
|
+
end_column: last_loc&.end_column || 0,
|
596
623
|
)
|
597
624
|
end
|
598
625
|
end
|
@@ -600,14 +627,6 @@ module RBI
|
|
600
627
|
class ConstBuilder < ASTVisitor
|
601
628
|
extend T::Sig
|
602
629
|
|
603
|
-
sig { params(node: T.nilable(AST::Node)).returns(T.nilable(String)) }
|
604
|
-
def self.visit(node)
|
605
|
-
v = ConstBuilder.new
|
606
|
-
v.visit(node)
|
607
|
-
return nil if v.names.empty?
|
608
|
-
v.names.join("::")
|
609
|
-
end
|
610
|
-
|
611
630
|
sig { returns(T::Array[String]) }
|
612
631
|
attr_accessor :names
|
613
632
|
|
@@ -617,9 +636,23 @@ module RBI
|
|
617
636
|
@names = T.let([], T::Array[String])
|
618
637
|
end
|
619
638
|
|
639
|
+
class << self
|
640
|
+
extend T::Sig
|
641
|
+
|
642
|
+
sig { params(node: T.nilable(AST::Node)).returns(T.nilable(String)) }
|
643
|
+
def visit(node)
|
644
|
+
v = ConstBuilder.new
|
645
|
+
v.visit(node)
|
646
|
+
return if v.names.empty?
|
647
|
+
|
648
|
+
v.names.join("::")
|
649
|
+
end
|
650
|
+
end
|
651
|
+
|
620
652
|
sig { override.params(node: T.nilable(AST::Node)).void }
|
621
653
|
def visit(node)
|
622
654
|
return unless node
|
655
|
+
|
623
656
|
case node.type
|
624
657
|
when :const, :casgn
|
625
658
|
visit(node.children[0])
|
@@ -635,15 +668,8 @@ module RBI
|
|
635
668
|
class SigBuilder < ASTVisitor
|
636
669
|
extend T::Sig
|
637
670
|
|
638
|
-
sig { params(node: AST::Node).returns(Sig) }
|
639
|
-
def self.build(node)
|
640
|
-
v = SigBuilder.new
|
641
|
-
v.visit_all(node.children)
|
642
|
-
v.current
|
643
|
-
end
|
644
|
-
|
645
671
|
sig { returns(Sig) }
|
646
|
-
|
672
|
+
attr_reader :current
|
647
673
|
|
648
674
|
sig { void }
|
649
675
|
def initialize
|
@@ -651,9 +677,21 @@ module RBI
|
|
651
677
|
@current = T.let(Sig.new, Sig)
|
652
678
|
end
|
653
679
|
|
680
|
+
class << self
|
681
|
+
extend T::Sig
|
682
|
+
|
683
|
+
sig { params(node: AST::Node).returns(Sig) }
|
684
|
+
def build(node)
|
685
|
+
v = SigBuilder.new
|
686
|
+
v.visit_all(node.children)
|
687
|
+
v.current
|
688
|
+
end
|
689
|
+
end
|
690
|
+
|
654
691
|
sig { override.params(node: T.nilable(AST::Node)).void }
|
655
692
|
def visit(node)
|
656
693
|
return unless node
|
694
|
+
|
657
695
|
case node.type
|
658
696
|
when :send
|
659
697
|
visit_send(node)
|
@@ -703,15 +741,19 @@ module RBI
|
|
703
741
|
end
|
704
742
|
|
705
743
|
class Loc
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
744
|
+
class << self
|
745
|
+
extend T::Sig
|
746
|
+
|
747
|
+
sig { params(file: String, ast_loc: T.any(::Parser::Source::Map, ::Parser::Source::Range)).returns(Loc) }
|
748
|
+
def from_ast_loc(file, ast_loc)
|
749
|
+
Loc.new(
|
750
|
+
file: file,
|
751
|
+
begin_line: ast_loc.line,
|
752
|
+
begin_column: ast_loc.column,
|
753
|
+
end_line: ast_loc.last_line,
|
754
|
+
end_column: ast_loc.last_column,
|
755
|
+
)
|
756
|
+
end
|
715
757
|
end
|
716
758
|
end
|
717
759
|
end
|
data/lib/rbi/printer.rb
CHANGED
@@ -22,7 +22,7 @@ module RBI
|
|
22
22
|
out: T.any(IO, StringIO),
|
23
23
|
indent: Integer,
|
24
24
|
print_locs: T::Boolean,
|
25
|
-
max_line_length: T.nilable(Integer)
|
25
|
+
max_line_length: T.nilable(Integer),
|
26
26
|
).void
|
27
27
|
end
|
28
28
|
def initialize(out: $stdout, indent: 0, print_locs: false, max_line_length: nil)
|
@@ -82,6 +82,7 @@ module RBI
|
|
82
82
|
sig { override.params(node: T.nilable(Node)).void }
|
83
83
|
def visit(node)
|
84
84
|
return unless node
|
85
|
+
|
85
86
|
node.accept_printer(self)
|
86
87
|
end
|
87
88
|
|
@@ -122,7 +123,7 @@ module RBI
|
|
122
123
|
out: T.any(IO, StringIO),
|
123
124
|
indent: Integer,
|
124
125
|
print_locs: T::Boolean,
|
125
|
-
max_line_length: T.nilable(Integer)
|
126
|
+
max_line_length: T.nilable(Integer),
|
126
127
|
).void
|
127
128
|
end
|
128
129
|
def print(out: $stdout, indent: 0, print_locs: false, max_line_length: nil)
|
@@ -149,7 +150,7 @@ module RBI
|
|
149
150
|
out: T.any(IO, StringIO),
|
150
151
|
indent: Integer,
|
151
152
|
print_locs: T::Boolean,
|
152
|
-
max_line_length: T.nilable(Integer)
|
153
|
+
max_line_length: T.nilable(Integer),
|
153
154
|
).void
|
154
155
|
end
|
155
156
|
def print(out: $stdout, indent: 0, print_locs: false, max_line_length: nil)
|
@@ -170,6 +171,7 @@ module RBI
|
|
170
171
|
return unless previous_node
|
171
172
|
return if previous_node.is_a?(BlankLine)
|
172
173
|
return if previous_node.oneline? && oneline?
|
174
|
+
|
173
175
|
v.printn
|
174
176
|
end
|
175
177
|
|
@@ -36,7 +36,7 @@ module RBI
|
|
36
36
|
|
37
37
|
attr.sigs << Sig.new(
|
38
38
|
params: params,
|
39
|
-
return_type: "T.untyped"
|
39
|
+
return_type: "T.untyped",
|
40
40
|
)
|
41
41
|
add_todo_comment(attr)
|
42
42
|
end
|
@@ -47,7 +47,7 @@ module RBI
|
|
47
47
|
|
48
48
|
method.sigs << Sig.new(
|
49
49
|
params: method.params.map { |param| SigParam.new(param.name, "T.untyped") },
|
50
|
-
return_type: "T.untyped"
|
50
|
+
return_type: "T.untyped",
|
51
51
|
)
|
52
52
|
add_todo_comment(method)
|
53
53
|
end
|
@@ -30,6 +30,7 @@ module RBI
|
|
30
30
|
sig { params(node: NodeWithComments).void }
|
31
31
|
def annotate_node(node)
|
32
32
|
return if node.annotations.one?(@annotation)
|
33
|
+
|
33
34
|
node.comments << Comment.new("@#{@annotation}")
|
34
35
|
end
|
35
36
|
|
@@ -49,7 +50,7 @@ module RBI
|
|
49
50
|
visitor = Rewriters::Annotate.new(
|
50
51
|
annotation,
|
51
52
|
annotate_scopes: annotate_scopes,
|
52
|
-
annotate_properties: annotate_properties
|
53
|
+
annotate_properties: annotate_properties,
|
53
54
|
)
|
54
55
|
visitor.visit(self)
|
55
56
|
end
|
@@ -47,16 +47,20 @@ module RBI
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
right.
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
50
|
+
class << self
|
51
|
+
extend T::Sig
|
52
|
+
|
53
|
+
sig { params(left: Tree, right: Tree, left_name: String, right_name: String, keep: Keep).returns(MergeTree) }
|
54
|
+
def merge_trees(left, right, left_name: "left", right_name: "right", keep: Keep::NONE)
|
55
|
+
left.nest_singleton_methods!
|
56
|
+
right.nest_singleton_methods!
|
57
|
+
rewriter = Rewriters::Merge.new(left_name: left_name, right_name: right_name, keep: keep)
|
58
|
+
rewriter.merge(left)
|
59
|
+
rewriter.merge(right)
|
60
|
+
tree = rewriter.tree
|
61
|
+
ConflictTreeMerger.new.visit(tree)
|
62
|
+
tree
|
63
|
+
end
|
60
64
|
end
|
61
65
|
|
62
66
|
sig { returns(MergeTree) }
|
@@ -293,6 +297,7 @@ module RBI
|
|
293
297
|
parent = T.let(parent_tree, T.nilable(Node))
|
294
298
|
while parent
|
295
299
|
return parent if parent.is_a?(ConflictTree)
|
300
|
+
|
296
301
|
parent = parent.parent_tree
|
297
302
|
end
|
298
303
|
nil
|
@@ -305,6 +310,7 @@ module RBI
|
|
305
310
|
sig { override.params(other: Node).void }
|
306
311
|
def merge_with(other)
|
307
312
|
return unless other.is_a?(NodeWithComments)
|
313
|
+
|
308
314
|
other.comments.each do |comment|
|
309
315
|
comments << comment unless comments.include?(comment)
|
310
316
|
end
|
@@ -332,7 +338,7 @@ module RBI
|
|
332
338
|
loc: T.nilable(Loc),
|
333
339
|
comments: T::Array[Comment],
|
334
340
|
conflicts: T::Array[Rewriters::Merge::Conflict],
|
335
|
-
block: T.nilable(T.proc.params(node: Tree).void)
|
341
|
+
block: T.nilable(T.proc.params(node: Tree).void),
|
336
342
|
).void
|
337
343
|
end
|
338
344
|
def initialize(loc: nil, comments: [], conflicts: [], &block)
|
@@ -406,12 +412,14 @@ module RBI
|
|
406
412
|
def compatible_with?(other)
|
407
413
|
return false unless other.is_a?(Attr)
|
408
414
|
return false unless names == other.names
|
415
|
+
|
409
416
|
sigs.empty? || other.sigs.empty? || sigs == other.sigs
|
410
417
|
end
|
411
418
|
|
412
419
|
sig { override.params(other: Node).void }
|
413
420
|
def merge_with(other)
|
414
421
|
return unless other.is_a?(Attr)
|
422
|
+
|
415
423
|
super
|
416
424
|
other.sigs.each do |sig|
|
417
425
|
sigs << sig unless sigs.include?(sig)
|
@@ -454,12 +462,14 @@ module RBI
|
|
454
462
|
return false unless other.is_a?(Method)
|
455
463
|
return false unless name == other.name
|
456
464
|
return false unless params == other.params
|
465
|
+
|
457
466
|
sigs.empty? || other.sigs.empty? || sigs == other.sigs
|
458
467
|
end
|
459
468
|
|
460
469
|
sig { override.params(other: Node).void }
|
461
470
|
def merge_with(other)
|
462
471
|
return unless other.is_a?(Method)
|
472
|
+
|
463
473
|
super
|
464
474
|
other.sigs.each do |sig|
|
465
475
|
sigs << sig unless sigs.include?(sig)
|
@@ -545,6 +555,7 @@ module RBI
|
|
545
555
|
sig { override.params(other: Node).void }
|
546
556
|
def merge_with(other)
|
547
557
|
return unless other.is_a?(TEnumBlock)
|
558
|
+
|
548
559
|
super
|
549
560
|
other.names.each do |name|
|
550
561
|
names << name unless names.include?(name)
|
@@ -625,7 +636,7 @@ module RBI
|
|
625
636
|
left: Scope,
|
626
637
|
right: Scope,
|
627
638
|
left_name: String,
|
628
|
-
right_name: String
|
639
|
+
right_name: String,
|
629
640
|
).void
|
630
641
|
end
|
631
642
|
def initialize(left:, right:, left_name: "left", right_name: "right")
|
@@ -48,18 +48,6 @@ module RBI
|
|
48
48
|
class RemoveKnownDefinitions < Visitor
|
49
49
|
extend T::Sig
|
50
50
|
|
51
|
-
sig do
|
52
|
-
params(
|
53
|
-
tree: Tree,
|
54
|
-
index: Index
|
55
|
-
).returns([Tree, T::Array[Operation]])
|
56
|
-
end
|
57
|
-
def self.remove(tree, index)
|
58
|
-
v = RemoveKnownDefinitions.new(index)
|
59
|
-
v.visit(tree)
|
60
|
-
[tree, v.operations]
|
61
|
-
end
|
62
|
-
|
63
51
|
sig { returns(T::Array[Operation]) }
|
64
52
|
attr_reader :operations
|
65
53
|
|
@@ -70,6 +58,22 @@ module RBI
|
|
70
58
|
@operations = T.let([], T::Array[Operation])
|
71
59
|
end
|
72
60
|
|
61
|
+
class << self
|
62
|
+
extend T::Sig
|
63
|
+
|
64
|
+
sig do
|
65
|
+
params(
|
66
|
+
tree: Tree,
|
67
|
+
index: Index,
|
68
|
+
).returns([Tree, T::Array[Operation]])
|
69
|
+
end
|
70
|
+
def remove(tree, index)
|
71
|
+
v = RemoveKnownDefinitions.new(index)
|
72
|
+
v.visit(tree)
|
73
|
+
[tree, v.operations]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
73
77
|
sig { params(nodes: T::Array[Node]).void }
|
74
78
|
def visit_all(nodes)
|
75
79
|
nodes.dup.each { |node| visit(node) }
|
@@ -11,20 +11,32 @@ module RBI
|
|
11
11
|
sort_node_names!(node) if node
|
12
12
|
|
13
13
|
return unless node.is_a?(Tree)
|
14
|
+
|
14
15
|
visit_all(node.nodes)
|
15
16
|
original_order = node.nodes.map.with_index.to_h
|
16
|
-
node.nodes.sort! do |a, b|
|
17
|
-
# First we try to compare the nodes by their node rank (based on the node type)
|
18
|
-
res = node_rank(a) <=> node_rank(b)
|
19
|
-
next res if res != 0 # we can sort the nodes by their rank, let's stop here
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
# The child nodes could contain private/protected markers. If so, they should not be moved in the file.
|
19
|
+
# Otherwise, some methods could see their privacy change. To avoid that problem, divide the array of child
|
20
|
+
# nodes into chunks based on whether any Visibility nodes appear, and sort the chunks independently. This
|
21
|
+
# applies the ordering rules from the node_rank method as much as possible, while preserving visibility.
|
22
|
+
sorted_nodes = node.nodes.chunk do |n|
|
23
|
+
n.is_a?(Visibility)
|
24
|
+
end.flat_map do |_, nodes|
|
25
|
+
nodes.sort! do |a, b|
|
26
|
+
# First we try to compare the nodes by their node rank (based on the node type)
|
27
|
+
res = node_rank(a) <=> node_rank(b)
|
28
|
+
next res if res != 0 # we can sort the nodes by their rank, let's stop here
|
29
|
+
|
30
|
+
# Then, if the nodes ranks are the same (res == 0), we try to compare the nodes by their name
|
31
|
+
res = node_name(a) <=> node_name(b)
|
32
|
+
next res if res && res != 0 # we can sort the nodes by their name, let's stop here
|
24
33
|
|
25
|
-
|
26
|
-
|
34
|
+
# Finally, if the two nodes have the same rank and the same name or at least one node is anonymous then,
|
35
|
+
T.must(original_order[a]) <=> T.must(original_order[b]) # we keep the original order
|
36
|
+
end
|
27
37
|
end
|
38
|
+
|
39
|
+
node.nodes.replace(sorted_nodes)
|
28
40
|
end
|
29
41
|
|
30
42
|
private
|
@@ -81,10 +93,12 @@ module RBI
|
|
81
93
|
sig { params(node: Node).returns(T.nilable(String)) }
|
82
94
|
def node_name(node)
|
83
95
|
case node
|
84
|
-
when Module, Class, Struct, Const, Method, Helper,
|
96
|
+
when Module, Class, Struct, Const, Method, Helper, RequiresAncestor
|
85
97
|
node.name
|
86
98
|
when Attr
|
87
99
|
node.names.first.to_s
|
100
|
+
when TStructField, Mixin
|
101
|
+
nil # we never want to sort these nodes by their name
|
88
102
|
end
|
89
103
|
end
|
90
104
|
|
data/lib/rbi/version.rb
CHANGED
data/lib/rbi.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Terrasa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sorbet-runtime
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.5.6
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.5.6
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
- ruby@shopify.com
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.4.14
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: RBI generation framework
|