rbi 0.0.10 → 0.0.13

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: b81ff4cdb9cb4776c5592c2838906188b7db79620511303a209d6d7ae395c491
4
- data.tar.gz: 9da4440f160522287e3e9aca18b4d535759b11ebe59fae994d6f51be473e1e2f
3
+ metadata.gz: c5ef2a157e342a16c69748e0f09b67839152d10e99a3b7eab4da23354b8993f9
4
+ data.tar.gz: 6622c783e58b67a950e4661a025f8d0a9508612eda9ee53af45f72e6c5057286
5
5
  SHA512:
6
- metadata.gz: c7b23d94ec81f396057fe0aeb60f75d46799241ec61e097096f6b65cd9d1730fe6ab3bab0442e2f44c62c82e31481d5c26d127b84715ec8fd74fcee939d96857
7
- data.tar.gz: 1fee917b50d5931574db3159349765d5a0d3b50ed12628afdf458eb011fd37bd140025588fdceb2124afc3ff7c5e8073b45bdd2ecfc3eb601ee2be6788f0fd29
6
+ metadata.gz: 598e6384b4aca8b6db5aa97d6a00e6a75cb1bb4273d5401006c969c4d89730797942c8d0ff7fed0a8da25f6170747126c064c6aadbec210ebb28e4781772ab26
7
+ data.tar.gz: 6021bd1134be4dfd834ece8648ea904ad30666216411c7524a9f4245f14ecab7b1e6da9d013a8c0bb4a9620fde7db83190b54f7bb512f7d1d23275300112482e
@@ -0,0 +1,66 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module RBI
5
+ class Formatter
6
+ extend T::Sig
7
+
8
+ sig { returns(T::Boolean) }
9
+ attr_accessor :add_sig_templates, :group_nodes, :nest_singleton_methods, :nest_non_public_methods, :sort_nodes
10
+
11
+ sig { returns(T.nilable(Integer)) }
12
+ attr_accessor :max_line_length
13
+
14
+ sig do
15
+ params(
16
+ add_sig_templates: T::Boolean,
17
+ group_nodes: T::Boolean,
18
+ max_line_length: T.nilable(Integer),
19
+ nest_singleton_methods: T::Boolean,
20
+ nest_non_public_methods: T::Boolean,
21
+ sort_nodes: T::Boolean
22
+ ).void
23
+ end
24
+ def initialize(
25
+ add_sig_templates: false,
26
+ group_nodes: false,
27
+ max_line_length: nil,
28
+ nest_singleton_methods: false,
29
+ nest_non_public_methods: false,
30
+ sort_nodes: false
31
+ )
32
+ @add_sig_templates = add_sig_templates
33
+ @group_nodes = group_nodes
34
+ @max_line_length = max_line_length
35
+ @nest_singleton_methods = nest_singleton_methods
36
+ @nest_non_public_methods = nest_non_public_methods
37
+ @sort_nodes = sort_nodes
38
+ end
39
+
40
+ sig { params(file: RBI::File).returns(String) }
41
+ def print_file(file)
42
+ format_file(file)
43
+ file.string(max_line_length: @max_line_length)
44
+ end
45
+
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
+ sig { params(file: RBI::File).void }
53
+ def format_file(file)
54
+ format_tree(file.root)
55
+ end
56
+
57
+ sig { params(tree: RBI::Tree).void }
58
+ def format_tree(tree)
59
+ tree.add_sig_templates! if @add_sig_templates
60
+ tree.nest_singleton_methods! if @nest_singleton_methods
61
+ tree.nest_non_public_methods! if @nest_non_public_methods
62
+ tree.group_nodes! if @group_nodes
63
+ tree.sort_nodes! if @sort_nodes
64
+ end
65
+ end
66
+ end
data/lib/rbi/model.rb CHANGED
@@ -1026,7 +1026,7 @@ module RBI
1026
1026
  attr_accessor :return_type
1027
1027
 
1028
1028
  sig { returns(T::Boolean) }
1029
- attr_accessor :is_abstract, :is_override, :is_overridable
1029
+ attr_accessor :is_abstract, :is_override, :is_overridable, :is_final
1030
1030
 
1031
1031
  sig { returns(T::Array[String]) }
1032
1032
  attr_reader :type_params
@@ -1041,6 +1041,7 @@ module RBI
1041
1041
  is_abstract: T::Boolean,
1042
1042
  is_override: T::Boolean,
1043
1043
  is_overridable: T::Boolean,
1044
+ is_final: T::Boolean,
1044
1045
  type_params: T::Array[String],
1045
1046
  checked: T.nilable(Symbol),
1046
1047
  loc: T.nilable(Loc),
@@ -1053,6 +1054,7 @@ module RBI
1053
1054
  is_abstract: false,
1054
1055
  is_override: false,
1055
1056
  is_overridable: false,
1057
+ is_final: false,
1056
1058
  type_params: [],
1057
1059
  checked: nil,
1058
1060
  loc: nil,
@@ -1064,6 +1066,7 @@ module RBI
1064
1066
  @is_abstract = is_abstract
1065
1067
  @is_override = is_override
1066
1068
  @is_overridable = is_overridable
1069
+ @is_final = is_final
1067
1070
  @type_params = type_params
1068
1071
  @checked = checked
1069
1072
  block&.call(self)
@@ -1078,7 +1081,7 @@ module RBI
1078
1081
  def ==(other)
1079
1082
  return false unless other.is_a?(Sig)
1080
1083
  params == other.params && return_type == other.return_type && is_abstract == other.is_abstract &&
1081
- is_override == other.is_override && is_overridable == other.is_overridable &&
1084
+ is_override == other.is_override && is_overridable == other.is_overridable && is_final == other.is_final &&
1082
1085
  type_params == other.type_params && checked == other.checked
1083
1086
  end
1084
1087
  end
data/lib/rbi/parser.rb CHANGED
@@ -289,7 +289,14 @@ module RBI
289
289
  names = node.children[2..-1].map { |child| parse_name(child) }
290
290
  MixesInClassMethods.new(*names, loc: loc, comments: comments)
291
291
  when :public, :protected, :private
292
- visibility = Visibility.new(method_name, loc: loc)
292
+ visibility = case method_name
293
+ when :protected
294
+ Protected.new(loc: loc)
295
+ when :private
296
+ Private.new(loc: loc)
297
+ else
298
+ Public.new(loc: loc)
299
+ end
293
300
  nested_node = node.children[2]
294
301
  case nested_node&.type
295
302
  when :def, :defs
@@ -422,7 +429,14 @@ module RBI
422
429
  sig { params(node: AST::Node).returns(TEnumBlock) }
423
430
  def parse_enum(node)
424
431
  enum = TEnumBlock.new
425
- node.children[2].children.each do |child|
432
+
433
+ body = if node.children[2].type == :begin
434
+ node.children[2].children
435
+ else
436
+ [node.children[2]]
437
+ end
438
+
439
+ body.each do |child|
426
440
  enum << parse_name(child)
427
441
  end
428
442
  enum.loc = node_loc(node)
@@ -561,7 +575,7 @@ module RBI
561
575
  sig { params(node: AST::Node).returns(Sig) }
562
576
  def self.build(node)
563
577
  v = SigBuilder.new
564
- v.visit_all(node.children[2..-1])
578
+ v.visit_all(node.children)
565
579
  v.current
566
580
  end
567
581
 
@@ -588,6 +602,9 @@ module RBI
588
602
  visit(node.children[0]) if node.children[0]
589
603
  name = node.children[1]
590
604
  case name
605
+ when :sig
606
+ arg = node.children[2]
607
+ @current.is_final = arg && arg.children[0] == :final
591
608
  when :abstract
592
609
  @current.is_abstract = true
593
610
  when :override
data/lib/rbi/printer.rb CHANGED
@@ -117,16 +117,23 @@ module RBI
117
117
  end
118
118
  end
119
119
 
120
- sig { params(out: T.any(IO, StringIO), indent: Integer, print_locs: T::Boolean).void }
121
- def print(out: $stdout, indent: 0, print_locs: false)
122
- p = Printer.new(out: out, indent: indent, print_locs: print_locs)
120
+ sig do
121
+ params(
122
+ out: T.any(IO, StringIO),
123
+ indent: Integer,
124
+ print_locs: T::Boolean,
125
+ max_line_length: T.nilable(Integer)
126
+ ).void
127
+ end
128
+ def print(out: $stdout, indent: 0, print_locs: false, max_line_length: nil)
129
+ p = Printer.new(out: out, indent: indent, print_locs: print_locs, max_line_length: max_line_length)
123
130
  p.visit_file(self)
124
131
  end
125
132
 
126
- sig { params(indent: Integer, print_locs: T::Boolean).returns(String) }
127
- def string(indent: 0, print_locs: false)
133
+ sig { params(indent: Integer, print_locs: T::Boolean, max_line_length: T.nilable(Integer)).returns(String) }
134
+ def string(indent: 0, print_locs: false, max_line_length: nil)
128
135
  out = StringIO.new
129
- print(out: out, indent: indent, print_locs: print_locs)
136
+ print(out: out, indent: indent, print_locs: print_locs, max_line_length: max_line_length)
130
137
  out.string
131
138
  end
132
139
  end
@@ -193,7 +200,7 @@ module RBI
193
200
  end
194
201
 
195
202
  lines.each do |line|
196
- text = line.strip
203
+ text = line.rstrip
197
204
  v.printt("#")
198
205
  v.print(" #{text}") unless text.empty?
199
206
  v.printn
@@ -448,7 +455,7 @@ module RBI
448
455
 
449
456
  sig { returns(T::Array[String]) }
450
457
  def comments_lines
451
- comments.flat_map { |comment| comment.text.lines.map(&:strip) }
458
+ comments.flat_map { |comment| comment.text.lines.map(&:rstrip) }
452
459
  end
453
460
  end
454
461
 
@@ -663,7 +670,9 @@ module RBI
663
670
 
664
671
  sig { params(v: Printer).void }
665
672
  def print_as_line(v)
666
- v.printt("sig { ")
673
+ v.printt("sig")
674
+ v.print("(:final)") if is_final
675
+ v.print(" { ")
667
676
  sig_modifiers.each do |modifier|
668
677
  v.print("#{modifier}.")
669
678
  end
@@ -751,7 +760,7 @@ module RBI
751
760
 
752
761
  sig { returns(T::Array[String]) }
753
762
  def comments_lines
754
- comments.flat_map { |comment| comment.text.lines.map(&:strip) }
763
+ comments.flat_map { |comment| comment.text.lines.map(&:rstrip) }
755
764
  end
756
765
  end
757
766
 
@@ -47,6 +47,8 @@ module RBI
47
47
  sig { returns(Group::Kind) }
48
48
  def group_kind
49
49
  case self
50
+ when Group
51
+ kind
50
52
  when Include, Extend
51
53
  Group::Kind::Mixins
52
54
  when RequiresAncestor
data/lib/rbi/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module RBI
5
- VERSION = "0.0.10"
5
+ VERSION = "0.0.13"
6
6
  end
data/lib/rbi.rb CHANGED
@@ -23,4 +23,5 @@ require "rbi/rewriters/remove_known_definitions"
23
23
  require "rbi/rewriters/sort_nodes"
24
24
  require "rbi/parser"
25
25
  require "rbi/printer"
26
+ require "rbi/formatter"
26
27
  require "rbi/version"
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.10
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-26 00:00:00.000000000 Z
11
+ date: 2022-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -77,6 +77,7 @@ files:
77
77
  - README.md
78
78
  - Rakefile
79
79
  - lib/rbi.rb
80
+ - lib/rbi/formatter.rb
80
81
  - lib/rbi/index.rb
81
82
  - lib/rbi/loc.rb
82
83
  - lib/rbi/model.rb