rbi 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +9 -5
- data/README.md +38 -10
- data/Rakefile +2 -0
- data/lib/rbi/index.rb +186 -0
- data/lib/rbi/loc.rb +36 -0
- data/lib/rbi/model.rb +1251 -0
- data/lib/rbi/parser.rb +568 -0
- data/lib/rbi/printer.rb +756 -0
- data/lib/rbi/rewriters/add_sig_templates.rb +71 -0
- data/lib/rbi/rewriters/group_nodes.rb +104 -0
- data/lib/rbi/rewriters/merge_trees.rb +629 -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 +4 -1
- data/lib/rbi/visitor.rb +19 -0
- data/lib/rbi.rb +17 -5
- metadata +34 -67
- data/exe/rbi +0 -7
- data/lib/rbi/cli.rb +0 -19
@@ -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
|
+
original_order = node.nodes.map.with_index.to_h
|
14
|
+
node.nodes.sort! do |a, b|
|
15
|
+
res = node_rank(a) <=> node_rank(b)
|
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
|
+
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 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
|
+
when Method
|
35
|
+
if node.name == "initialize"
|
36
|
+
71
|
37
|
+
elsif !node.is_singleton
|
38
|
+
72
|
39
|
+
else
|
40
|
+
73
|
41
|
+
end
|
42
|
+
when Scope, Const then 80
|
43
|
+
else
|
44
|
+
100
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
sig { params(kind: Group::Kind).returns(Integer) }
|
49
|
+
def group_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, Struct, 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
|
data/lib/rbi.rb
CHANGED
@@ -1,11 +1,23 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "sorbet-runtime"
|
4
|
-
require "
|
5
|
-
|
6
|
-
require "rbi/version"
|
7
|
-
require "rbi/cli"
|
5
|
+
require "stringio"
|
8
6
|
|
9
7
|
module RBI
|
10
8
|
class Error < StandardError; end
|
11
9
|
end
|
10
|
+
|
11
|
+
require "rbi/loc"
|
12
|
+
require "rbi/model"
|
13
|
+
require "rbi/visitor"
|
14
|
+
require "rbi/index"
|
15
|
+
require "rbi/rewriters/add_sig_templates"
|
16
|
+
require "rbi/rewriters/merge_trees"
|
17
|
+
require "rbi/rewriters/nest_singleton_methods"
|
18
|
+
require "rbi/rewriters/nest_non_public_methods"
|
19
|
+
require "rbi/rewriters/group_nodes"
|
20
|
+
require "rbi/rewriters/sort_nodes"
|
21
|
+
require "rbi/parser"
|
22
|
+
require "rbi/printer"
|
23
|
+
require "rbi/version"
|
metadata
CHANGED
@@ -1,59 +1,17 @@
|
|
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.5
|
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-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
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
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '5.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '5.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: sorbet-runtime
|
14
|
+
name: ast
|
57
15
|
requirement: !ruby/object:Gem::Requirement
|
58
16
|
requirements:
|
59
17
|
- - ">="
|
@@ -67,35 +25,35 @@ dependencies:
|
|
67
25
|
- !ruby/object:Gem::Version
|
68
26
|
version: '0'
|
69
27
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
28
|
+
name: parser
|
71
29
|
requirement: !ruby/object:Gem::Requirement
|
72
30
|
requirements:
|
73
|
-
- - "
|
31
|
+
- - ">="
|
74
32
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
33
|
+
version: '0'
|
76
34
|
type: :runtime
|
77
35
|
prerelease: false
|
78
36
|
version_requirements: !ruby/object:Gem::Requirement
|
79
37
|
requirements:
|
80
|
-
- - "
|
38
|
+
- - ">="
|
81
39
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
40
|
+
version: '0'
|
83
41
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
42
|
+
name: sorbet-runtime
|
85
43
|
requirement: !ruby/object:Gem::Requirement
|
86
44
|
requirements:
|
87
45
|
- - ">="
|
88
46
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0
|
47
|
+
version: '0'
|
90
48
|
type: :runtime
|
91
49
|
prerelease: false
|
92
50
|
version_requirements: !ruby/object:Gem::Requirement
|
93
51
|
requirements:
|
94
52
|
- - ">="
|
95
53
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0
|
54
|
+
version: '0'
|
97
55
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
56
|
+
name: unparser
|
99
57
|
requirement: !ruby/object:Gem::Requirement
|
100
58
|
requirements:
|
101
59
|
- - ">="
|
@@ -108,27 +66,36 @@ dependencies:
|
|
108
66
|
- - ">="
|
109
67
|
- !ruby/object:Gem::Version
|
110
68
|
version: '0'
|
111
|
-
description:
|
69
|
+
description:
|
112
70
|
email:
|
113
|
-
-
|
114
|
-
executables:
|
115
|
-
- rbi
|
71
|
+
- ruby@shopify.com
|
72
|
+
executables: []
|
116
73
|
extensions: []
|
117
74
|
extra_rdoc_files: []
|
118
75
|
files:
|
119
76
|
- Gemfile
|
120
77
|
- README.md
|
121
78
|
- Rakefile
|
122
|
-
- exe/rbi
|
123
79
|
- lib/rbi.rb
|
124
|
-
- lib/rbi/
|
80
|
+
- lib/rbi/index.rb
|
81
|
+
- lib/rbi/loc.rb
|
82
|
+
- lib/rbi/model.rb
|
83
|
+
- lib/rbi/parser.rb
|
84
|
+
- lib/rbi/printer.rb
|
85
|
+
- lib/rbi/rewriters/add_sig_templates.rb
|
86
|
+
- lib/rbi/rewriters/group_nodes.rb
|
87
|
+
- lib/rbi/rewriters/merge_trees.rb
|
88
|
+
- lib/rbi/rewriters/nest_non_public_methods.rb
|
89
|
+
- lib/rbi/rewriters/nest_singleton_methods.rb
|
90
|
+
- lib/rbi/rewriters/sort_nodes.rb
|
125
91
|
- lib/rbi/version.rb
|
92
|
+
- lib/rbi/visitor.rb
|
126
93
|
homepage: https://github.com/Shopify/rbi
|
127
94
|
licenses:
|
128
95
|
- MIT
|
129
96
|
metadata:
|
130
97
|
allowed_push_host: https://rubygems.org
|
131
|
-
post_install_message:
|
98
|
+
post_install_message:
|
132
99
|
rdoc_options: []
|
133
100
|
require_paths:
|
134
101
|
- lib
|
@@ -136,15 +103,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
103
|
requirements:
|
137
104
|
- - ">="
|
138
105
|
- !ruby/object:Gem::Version
|
139
|
-
version: 2.
|
106
|
+
version: 2.4.0
|
140
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
108
|
requirements:
|
142
109
|
- - ">="
|
143
110
|
- !ruby/object:Gem::Version
|
144
111
|
version: '0'
|
145
112
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
113
|
+
rubygems_version: 3.2.20
|
114
|
+
signing_key:
|
148
115
|
specification_version: 4
|
149
|
-
summary: RBI
|
116
|
+
summary: RBI generation framework
|
150
117
|
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
|