rbi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -5
- data/README.md +38 -10
- data/Rakefile +2 -0
- data/lib/rbi.rb +16 -5
- data/lib/rbi/index.rb +186 -0
- data/lib/rbi/loc.rb +36 -0
- data/lib/rbi/model.rb +879 -0
- data/lib/rbi/parser.rb +449 -0
- data/lib/rbi/printer.rb +643 -0
- data/lib/rbi/rewriters/group_nodes.rb +104 -0
- data/lib/rbi/rewriters/merge_trees.rb +587 -0
- data/lib/rbi/rewriters/nest_non_public_methods.rb +63 -0
- data/lib/rbi/rewriters/nest_singleton_methods.rb +40 -0
- data/lib/rbi/rewriters/sort_nodes.rb +84 -0
- data/lib/rbi/version.rb +5 -1
- data/lib/rbi/visitor.rb +19 -0
- metadata +36 -56
- data/exe/rbi +0 -7
- data/lib/rbi/cli.rb +0 -19
@@ -0,0 +1,63 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RBI
|
5
|
+
module Rewriters
|
6
|
+
class NestNonPublicMethods < Visitor
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
sig { override.params(node: T.nilable(Node)).void }
|
10
|
+
def visit(node)
|
11
|
+
return unless node
|
12
|
+
|
13
|
+
case node
|
14
|
+
when Tree
|
15
|
+
public_group = VisibilityGroup.new(Visibility::Public)
|
16
|
+
protected_group = VisibilityGroup.new(Visibility::Protected)
|
17
|
+
private_group = VisibilityGroup.new(Visibility::Private)
|
18
|
+
|
19
|
+
node.nodes.dup.each do |child|
|
20
|
+
visit(child)
|
21
|
+
next unless child.is_a?(Method)
|
22
|
+
child.detach
|
23
|
+
case child.visibility
|
24
|
+
when Visibility::Protected
|
25
|
+
protected_group << child
|
26
|
+
when Visibility::Private
|
27
|
+
private_group << child
|
28
|
+
else
|
29
|
+
public_group << child
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
node << public_group unless public_group.empty?
|
34
|
+
node << protected_group unless protected_group.empty?
|
35
|
+
node << private_group unless private_group.empty?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Tree
|
42
|
+
extend T::Sig
|
43
|
+
|
44
|
+
sig { void }
|
45
|
+
def nest_non_public_methods!
|
46
|
+
visitor = Rewriters::NestNonPublicMethods.new
|
47
|
+
visitor.visit(self)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class VisibilityGroup < Tree
|
52
|
+
extend T::Sig
|
53
|
+
|
54
|
+
sig { returns(Visibility) }
|
55
|
+
attr_reader :visibility
|
56
|
+
|
57
|
+
sig { params(visibility: Visibility).void }
|
58
|
+
def initialize(visibility)
|
59
|
+
super()
|
60
|
+
@visibility = visibility
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RBI
|
5
|
+
module Rewriters
|
6
|
+
class NestSingletonMethods < Visitor
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
sig { override.params(node: T.nilable(Node)).void }
|
10
|
+
def visit(node)
|
11
|
+
return unless node
|
12
|
+
|
13
|
+
case node
|
14
|
+
when Tree
|
15
|
+
singleton_class = SingletonClass.new
|
16
|
+
|
17
|
+
node.nodes.dup.each do |child|
|
18
|
+
visit(child)
|
19
|
+
next unless child.is_a?(Method) && child.is_singleton
|
20
|
+
child.detach
|
21
|
+
child.is_singleton = false
|
22
|
+
singleton_class << child
|
23
|
+
end
|
24
|
+
|
25
|
+
node << singleton_class unless singleton_class.empty?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Tree
|
32
|
+
extend T::Sig
|
33
|
+
|
34
|
+
sig { void }
|
35
|
+
def nest_singleton_methods!
|
36
|
+
visitor = Rewriters::NestSingletonMethods.new
|
37
|
+
visitor.visit(self)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RBI
|
5
|
+
module Rewriters
|
6
|
+
class SortNodes < Visitor
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
sig { override.params(node: T.nilable(Node)).void }
|
10
|
+
def visit(node)
|
11
|
+
return unless node.is_a?(Tree)
|
12
|
+
visit_all(node.nodes)
|
13
|
+
node.nodes.sort! do |a, b|
|
14
|
+
return 0 if a.is_a?(Mixin) || b.is_a?(Mixin)
|
15
|
+
|
16
|
+
res = node_rank(a) <=> node_rank(b)
|
17
|
+
res = node_name(a) <=> node_name(b) if res == 0
|
18
|
+
res || 0
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
sig { params(node: Node).returns(Integer) }
|
25
|
+
def node_rank(node)
|
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
|
34
|
+
when Method
|
35
|
+
if node.name == "initialize"
|
36
|
+
7
|
37
|
+
elsif !node.is_singleton
|
38
|
+
8
|
39
|
+
else
|
40
|
+
9
|
41
|
+
end
|
42
|
+
when Scope, Const then 9
|
43
|
+
else
|
44
|
+
10
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
sig { params(kind: Group::Kind).returns(Integer) }
|
49
|
+
def kind_rank(kind)
|
50
|
+
case kind
|
51
|
+
when Group::Kind::Mixins then 0
|
52
|
+
when Group::Kind::Helpers then 1
|
53
|
+
when Group::Kind::TypeMembers then 2
|
54
|
+
when Group::Kind::MixesInClassMethods then 3
|
55
|
+
when Group::Kind::TStructFields then 4
|
56
|
+
when Group::Kind::TEnums then 5
|
57
|
+
when Group::Kind::Inits then 6
|
58
|
+
when Group::Kind::Methods then 7
|
59
|
+
when Group::Kind::Consts then 8
|
60
|
+
else
|
61
|
+
T.absurd(kind)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
sig { params(node: Node).returns(T.nilable(String)) }
|
66
|
+
def node_name(node)
|
67
|
+
case node
|
68
|
+
when Module, Class, Const, Method, Helper, TStructField
|
69
|
+
node.name
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class Tree
|
76
|
+
extend T::Sig
|
77
|
+
|
78
|
+
sig { void }
|
79
|
+
def sort_nodes!
|
80
|
+
visitor = Rewriters::SortNodes.new
|
81
|
+
visitor.visit(self)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/rbi/version.rb
CHANGED
data/lib/rbi/visitor.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RBI
|
5
|
+
class Visitor
|
6
|
+
extend T::Helpers
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
abstract!
|
10
|
+
|
11
|
+
sig { abstract.params(node: T.nilable(Node)).void }
|
12
|
+
def visit(node); end
|
13
|
+
|
14
|
+
sig { params(nodes: T::Array[Node]).void }
|
15
|
+
def visit_all(nodes)
|
16
|
+
nodes.each { |node| visit(node) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,59 +1,31 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Terrasa
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: ast
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.17'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.17'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 13.0.1
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 13.0.1
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: minitest
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
17
|
+
- - ">="
|
46
18
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
-
type: :
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
49
21
|
prerelease: false
|
50
22
|
version_requirements: !ruby/object:Gem::Requirement
|
51
23
|
requirements:
|
52
|
-
- - "
|
24
|
+
- - ">="
|
53
25
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
26
|
+
version: '0'
|
55
27
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
28
|
+
name: parser
|
57
29
|
requirement: !ruby/object:Gem::Requirement
|
58
30
|
requirements:
|
59
31
|
- - ">="
|
@@ -67,35 +39,35 @@ dependencies:
|
|
67
39
|
- !ruby/object:Gem::Version
|
68
40
|
version: '0'
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
42
|
+
name: rake
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
72
44
|
requirements:
|
73
45
|
- - "~>"
|
74
46
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
47
|
+
version: '13.0'
|
76
48
|
type: :runtime
|
77
49
|
prerelease: false
|
78
50
|
version_requirements: !ruby/object:Gem::Requirement
|
79
51
|
requirements:
|
80
52
|
- - "~>"
|
81
53
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
54
|
+
version: '13.0'
|
83
55
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
56
|
+
name: sorbet-runtime
|
85
57
|
requirement: !ruby/object:Gem::Requirement
|
86
58
|
requirements:
|
87
59
|
- - ">="
|
88
60
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0
|
61
|
+
version: '0'
|
90
62
|
type: :runtime
|
91
63
|
prerelease: false
|
92
64
|
version_requirements: !ruby/object:Gem::Requirement
|
93
65
|
requirements:
|
94
66
|
- - ">="
|
95
67
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0
|
68
|
+
version: '0'
|
97
69
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
70
|
+
name: unparser
|
99
71
|
requirement: !ruby/object:Gem::Requirement
|
100
72
|
requirements:
|
101
73
|
- - ">="
|
@@ -108,27 +80,35 @@ dependencies:
|
|
108
80
|
- - ">="
|
109
81
|
- !ruby/object:Gem::Version
|
110
82
|
version: '0'
|
111
|
-
description:
|
83
|
+
description:
|
112
84
|
email:
|
113
85
|
- alexandre.terrasa@shopify.com
|
114
|
-
executables:
|
115
|
-
- rbi
|
86
|
+
executables: []
|
116
87
|
extensions: []
|
117
88
|
extra_rdoc_files: []
|
118
89
|
files:
|
119
90
|
- Gemfile
|
120
91
|
- README.md
|
121
92
|
- Rakefile
|
122
|
-
- exe/rbi
|
123
93
|
- lib/rbi.rb
|
124
|
-
- lib/rbi/
|
94
|
+
- lib/rbi/index.rb
|
95
|
+
- lib/rbi/loc.rb
|
96
|
+
- lib/rbi/model.rb
|
97
|
+
- lib/rbi/parser.rb
|
98
|
+
- lib/rbi/printer.rb
|
99
|
+
- lib/rbi/rewriters/group_nodes.rb
|
100
|
+
- lib/rbi/rewriters/merge_trees.rb
|
101
|
+
- lib/rbi/rewriters/nest_non_public_methods.rb
|
102
|
+
- lib/rbi/rewriters/nest_singleton_methods.rb
|
103
|
+
- lib/rbi/rewriters/sort_nodes.rb
|
125
104
|
- lib/rbi/version.rb
|
105
|
+
- lib/rbi/visitor.rb
|
126
106
|
homepage: https://github.com/Shopify/rbi
|
127
107
|
licenses:
|
128
108
|
- MIT
|
129
109
|
metadata:
|
130
110
|
allowed_push_host: https://rubygems.org
|
131
|
-
post_install_message:
|
111
|
+
post_install_message:
|
132
112
|
rdoc_options: []
|
133
113
|
require_paths:
|
134
114
|
- lib
|
@@ -136,15 +116,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
116
|
requirements:
|
137
117
|
- - ">="
|
138
118
|
- !ruby/object:Gem::Version
|
139
|
-
version: 2.
|
119
|
+
version: 2.4.0
|
140
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
121
|
requirements:
|
142
122
|
- - ">="
|
143
123
|
- !ruby/object:Gem::Version
|
144
124
|
version: '0'
|
145
125
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
126
|
+
rubygems_version: 3.2.20
|
127
|
+
signing_key:
|
148
128
|
specification_version: 4
|
149
|
-
summary: RBI
|
129
|
+
summary: RBI generation framework
|
150
130
|
test_files: []
|
data/exe/rbi
DELETED
data/lib/rbi/cli.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# typed: true
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module RBI
|
5
|
-
class CLI < ::Thor
|
6
|
-
extend T::Sig
|
7
|
-
|
8
|
-
map T.unsafe(%w[--version] => :__print_version)
|
9
|
-
|
10
|
-
desc "--version", "Show version"
|
11
|
-
def __print_version
|
12
|
-
puts "RBI v#{RBI::VERSION}"
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.exit_on_failure?
|
16
|
-
true
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|