rbi 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,18 +12,18 @@ module RBI
12
12
 
13
13
  case node
14
14
  when Tree
15
- public_group = VisibilityGroup.new(Visibility::Public)
16
- protected_group = VisibilityGroup.new(Visibility::Protected)
17
- private_group = VisibilityGroup.new(Visibility::Private)
15
+ public_group = VisibilityGroup.new(Public.new)
16
+ protected_group = VisibilityGroup.new(Protected.new)
17
+ private_group = VisibilityGroup.new(Private.new)
18
18
 
19
19
  node.nodes.dup.each do |child|
20
20
  visit(child)
21
21
  next unless child.is_a?(Method)
22
22
  child.detach
23
23
  case child.visibility
24
- when Visibility::Protected
24
+ when Protected
25
25
  protected_group << child
26
- when Visibility::Private
26
+ when Private
27
27
  private_group << child
28
28
  else
29
29
  public_group << child
@@ -10,11 +10,11 @@ module RBI
10
10
  def visit(node)
11
11
  return unless node.is_a?(Tree)
12
12
  visit_all(node.nodes)
13
+ original_order = node.nodes.map.with_index.to_h
13
14
  node.nodes.sort! do |a, b|
14
- return 0 if a.is_a?(Mixin) || b.is_a?(Mixin)
15
-
16
15
  res = node_rank(a) <=> node_rank(b)
17
16
  res = node_name(a) <=> node_name(b) if res == 0
17
+ res = (original_order[a] || 0) <=> (original_order[b] || 0) if res == 0
18
18
  res || 0
19
19
  end
20
20
  end
@@ -24,29 +24,29 @@ module RBI
24
24
  sig { params(node: Node).returns(Integer) }
25
25
  def node_rank(node)
26
26
  case node
27
- when Group then kind_rank(node.kind)
28
- when Include, Extend then 0
29
- when Helper then 1
30
- when TypeMember then 2
31
- when MixesInClassMethods then 3
32
- when TStructField then 4
33
- when TEnumBlock then 5
27
+ when Group then group_rank(node.kind)
28
+ when Include, Extend then 10
29
+ when Helper then 20
30
+ when TypeMember then 30
31
+ when MixesInClassMethods then 40
32
+ when TStructField then 50
33
+ when TEnumBlock then 60
34
34
  when Method
35
35
  if node.name == "initialize"
36
- 7
36
+ 71
37
37
  elsif !node.is_singleton
38
- 8
38
+ 72
39
39
  else
40
- 9
40
+ 73
41
41
  end
42
- when Scope, Const then 9
42
+ when Scope, Const then 80
43
43
  else
44
- 10
44
+ 100
45
45
  end
46
46
  end
47
47
 
48
48
  sig { params(kind: Group::Kind).returns(Integer) }
49
- def kind_rank(kind)
49
+ def group_rank(kind)
50
50
  case kind
51
51
  when Group::Kind::Mixins then 0
52
52
  when Group::Kind::Helpers then 1
@@ -65,7 +65,7 @@ module RBI
65
65
  sig { params(node: Node).returns(T.nilable(String)) }
66
66
  def node_name(node)
67
67
  case node
68
- when Module, Class, Const, Method, Helper, TStructField
68
+ when Module, Class, Struct, Const, Method, Helper, TStructField
69
69
  node.name
70
70
  end
71
71
  end
data/lib/rbi/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # frozen_string_literal: true
4
4
 
5
5
  module RBI
6
- VERSION = "0.0.2"
6
+ VERSION = "0.0.3"
7
7
  end
data/lib/rbi.rb CHANGED
@@ -12,6 +12,7 @@ require "rbi/loc"
12
12
  require "rbi/model"
13
13
  require "rbi/visitor"
14
14
  require "rbi/index"
15
+ require "rbi/rewriters/add_sig_templates"
15
16
  require "rbi/rewriters/merge_trees"
16
17
  require "rbi/rewriters/nest_singleton_methods"
17
18
  require "rbi/rewriters/nest_non_public_methods"
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.2
4
+ version: 0.0.3
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-08-03 00:00:00.000000000 Z
11
+ date: 2021-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -82,7 +82,7 @@ dependencies:
82
82
  version: '0'
83
83
  description:
84
84
  email:
85
- - alexandre.terrasa@shopify.com
85
+ - ruby@shopify.com
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
@@ -96,6 +96,7 @@ files:
96
96
  - lib/rbi/model.rb
97
97
  - lib/rbi/parser.rb
98
98
  - lib/rbi/printer.rb
99
+ - lib/rbi/rewriters/add_sig_templates.rb
99
100
  - lib/rbi/rewriters/group_nodes.rb
100
101
  - lib/rbi/rewriters/merge_trees.rb
101
102
  - lib/rbi/rewriters/nest_non_public_methods.rb