rbi 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad10c5d34005d6a802652c77c317986852dedeb6fb32203f04cb54af2e3390a5
4
- data.tar.gz: d502093f1ea3f802c525fa7c9c5065f5b83c164031a1a9882e783200cb58c06f
3
+ metadata.gz: fb13c49bd19a95d439f7249770add05929979892daa3ba9c55de8241a596a8d2
4
+ data.tar.gz: bc772396cd7997b9443782775854993cb9e4b0d1241415020c258aa8f49186b2
5
5
  SHA512:
6
- metadata.gz: 5e551429e890318d60b66b3331d001e1e9b0489746fbf218f5f347a6e2647e168c76eddcf5e4628e3128d7cda28d77a29bc872bd696cdfb347b78e98a839a2ba
7
- data.tar.gz: 60ec408e5cfc4b94157b6f8028c0b699ebf5e01632dc691adeff7f22c245a45abbe44d400533ddf526b32d8e9de9b4fbfa1f1e06a7ce450cf77911754633579e
6
+ metadata.gz: 9990c9fd5fa2bc0925f06ce07f02079165f431e9535874d0204b0e2afbc6ad1919578e3ecd13a33b69ef575ec84911fadb34d3a71df917437fd46182bb07aa6e
7
+ data.tar.gz: 2818b3db38a03e58eb8bd6dd160ca50fac237242192620a6910dd73c451a3ee90e5dd483502e721870329724f0b4237899225d3c4e5f429b37abd667e0183c87
data/lib/rbi/parser.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "unparser"
4
+ require "parser"
5
5
 
6
6
  module RBI
7
7
  class ParseError < StandardError
@@ -27,6 +27,12 @@ module RBI
27
27
  ::Parser::Builders::Default.emit_index = true
28
28
  ::Parser::Builders::Default.emit_arg_inside_procarg0 = true
29
29
 
30
+ sig { void }
31
+ def initialize
32
+ # Delay load unparser and only if it has not been loaded already.
33
+ require "unparser" unless defined?(::Unparser)
34
+ end
35
+
30
36
  sig { params(string: String).returns(Tree) }
31
37
  def self.parse_string(string)
32
38
  Parser.new.parse_string(string)
data/lib/rbi/printer.rb CHANGED
@@ -97,7 +97,7 @@ module RBI
97
97
  v.visit_all(comments)
98
98
  end
99
99
 
100
- unless root.empty?
100
+ unless root.empty? && root.comments.empty?
101
101
  v.printn if strictness || !comments.empty?
102
102
  v.visit(root)
103
103
  end
@@ -156,10 +156,18 @@ module RBI
156
156
 
157
157
  sig { override.params(v: Printer).void }
158
158
  def accept_printer(v)
159
- text = self.text.strip
160
- v.printt("#")
161
- v.print(" #{text}") unless text.empty?
162
- v.printn
159
+ lines = text.lines
160
+
161
+ if lines.empty?
162
+ v.printl("#")
163
+ end
164
+
165
+ lines.each do |line|
166
+ text = line.strip
167
+ v.printt("#")
168
+ v.print(" #{text}") unless text.empty?
169
+ v.printn
170
+ end
163
171
  end
164
172
  end
165
173
 
@@ -366,13 +374,14 @@ module RBI
366
374
  v.printt
367
375
  v.visit(param)
368
376
  v.print(",") if pindex < params.size - 1
369
- param.comments.each_with_index do |comment, cindex|
377
+
378
+ param.comments_lines.each_with_index do |comment, cindex|
370
379
  if cindex > 0
371
380
  param.print_comment_leading_space(v, last: pindex == params.size - 1)
372
381
  else
373
382
  v.print(" ")
374
383
  end
375
- v.print("# #{comment.text.strip}")
384
+ v.print("# #{comment}")
376
385
  end
377
386
  v.printn
378
387
  end
@@ -410,6 +419,11 @@ module RBI
410
419
  v.print(" " * (name.size + 1))
411
420
  v.print(" ") unless last
412
421
  end
422
+
423
+ sig { returns(T::Array[String]) }
424
+ def comments_lines
425
+ comments.flat_map { |comment| comment.text.lines.map(&:strip) }
426
+ end
413
427
  end
414
428
 
415
429
  class OptParam
@@ -576,13 +590,13 @@ module RBI
576
590
  v.printt
577
591
  v.visit(param)
578
592
  v.print(",") if pindex < params.size - 1
579
- param.comments.each_with_index do |comment, cindex|
593
+ param.comments_lines.each_with_index do |comment, cindex|
580
594
  if cindex == 0
581
595
  v.print(" ")
582
596
  else
583
597
  param.print_comment_leading_space(v, last: pindex == params.size - 1)
584
598
  end
585
- v.print("# #{comment.text.strip}")
599
+ v.print("# #{comment}")
586
600
  end
587
601
  v.printn
588
602
  end
@@ -633,6 +647,11 @@ module RBI
633
647
  v.print(" " * (name.size + type.size + 3))
634
648
  v.print(" ") unless last
635
649
  end
650
+
651
+ sig { returns(T::Array[String]) }
652
+ def comments_lines
653
+ comments.flat_map { |comment| comment.text.lines.map(&:strip) }
654
+ end
636
655
  end
637
656
 
638
657
  class TStructField
data/lib/rbi/version.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # typed: true
2
- # typed: false
3
2
  # frozen_string_literal: true
4
3
 
5
4
  module RBI
6
- VERSION = "0.0.4"
5
+ VERSION = "0.0.5"
7
6
  end
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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-08 00:00:00.000000000 Z
11
+ date: 2021-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast