rbi 0.0.11 → 0.0.12

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: 727196c54429957687b3624d4b5a895e526973b045689a7689edb9cd73c97ca9
4
- data.tar.gz: 115a6efabd78950aa980d0b03e3b9910f474ad03cdf04f7a87b56ed38bdc30b7
3
+ metadata.gz: ff552cac7ef282e9673502662c239c6e60e370d4d9e6d137db16ed03bd3c5a32
4
+ data.tar.gz: 6ca736d5854621dde27bafffd8ad4b393d2c60d5f7b9e4eba8ab938e7f9123f4
5
5
  SHA512:
6
- metadata.gz: 7357ca0bb3e8700a95d1ea6e285e710f3545a9016e36bc0a64fe0682da80328d5c645b4d6cd3d14bba14e7ccd6b9134c225944ce27625de6a26a995f5283d173
7
- data.tar.gz: 71559ec6d855d46d3ac7bb074dbfd24fa024aaa6563dd241a7c286b66d138bf18f6c6e688ee33df99bdc240cbd6f683ebc068cb5c98b7e2b37dde6d4c9debca8
6
+ metadata.gz: 9540175cf17bd99421f4c0e2d81dae2a6b79a0ba3528409c1aeb0fbc4923eb01b2b9a5d6d28a17c1b7d0ac4a4b06f10775ecabc460f54ad39fa5099256554730
7
+ data.tar.gz: 75a8657c94d508c5b53793be7b53fe6570850c6088cd67fc75c85b5d42555824b248d6f2c7a62527e8e50555276eb4e32ba33bb406c948d66a1f0a11f7f16014
@@ -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
@@ -561,7 +568,7 @@ module RBI
561
568
  sig { params(node: AST::Node).returns(Sig) }
562
569
  def self.build(node)
563
570
  v = SigBuilder.new
564
- v.visit_all(node.children[2..-1])
571
+ v.visit_all(node.children)
565
572
  v.current
566
573
  end
567
574
 
@@ -588,6 +595,9 @@ module RBI
588
595
  visit(node.children[0]) if node.children[0]
589
596
  name = node.children[1]
590
597
  case name
598
+ when :sig
599
+ arg = node.children[2]
600
+ @current.is_final = arg && arg.children[0] == :final
591
601
  when :abstract
592
602
  @current.is_abstract = true
593
603
  when :override
data/lib/rbi/printer.rb CHANGED
@@ -200,7 +200,7 @@ module RBI
200
200
  end
201
201
 
202
202
  lines.each do |line|
203
- text = line.strip
203
+ text = line.rstrip
204
204
  v.printt("#")
205
205
  v.print(" #{text}") unless text.empty?
206
206
  v.printn
@@ -455,7 +455,7 @@ module RBI
455
455
 
456
456
  sig { returns(T::Array[String]) }
457
457
  def comments_lines
458
- comments.flat_map { |comment| comment.text.lines.map(&:strip) }
458
+ comments.flat_map { |comment| comment.text.lines.map(&:rstrip) }
459
459
  end
460
460
  end
461
461
 
@@ -670,7 +670,9 @@ module RBI
670
670
 
671
671
  sig { params(v: Printer).void }
672
672
  def print_as_line(v)
673
- v.printt("sig { ")
673
+ v.printt("sig")
674
+ v.print("(:final)") if is_final
675
+ v.print(" { ")
674
676
  sig_modifiers.each do |modifier|
675
677
  v.print("#{modifier}.")
676
678
  end
@@ -758,7 +760,7 @@ module RBI
758
760
 
759
761
  sig { returns(T::Array[String]) }
760
762
  def comments_lines
761
- comments.flat_map { |comment| comment.text.lines.map(&:strip) }
763
+ comments.flat_map { |comment| comment.text.lines.map(&:rstrip) }
762
764
  end
763
765
  end
764
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.11"
5
+ VERSION = "0.0.12"
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.11
4
+ version: 0.0.12
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-27 00:00:00.000000000 Z
11
+ date: 2022-02-08 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