sord 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
- data/.github/ISSUE_TEMPLATE/feature-request.md +20 -0
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +17 -3
- data/lib/sord/rbi_generator.rb +19 -4
- data/lib/sord/type_converter.rb +11 -5
- data/lib/sord/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48989b3587651b3576af45f8ba0664eb5e49696e6c8e9e18deb2bce33d78651e
|
4
|
+
data.tar.gz: 2b0f10c99524c00ebe89d76eecab495bd38c55dc5a84a0e707b888030a07caf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6350ec6144be3d60d8056c0d25af71ad17c0960a1931e30cedb12fb1820461ed922fbad188b7ad6f8a3009a804311e6b2f63aae6bd938b7f036cfb00441db9ba
|
7
|
+
data.tar.gz: 2fffdecb428ab937948eebefa56aac39da39d4b1972ddc98d8d7d2d4ef37ee3f1fedecaa95146286d53707d8b8ccc16fa30d2aec9dcbe4eeb39369f2b4f4280c
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create an issue to report a bug
|
4
|
+
title: ''
|
5
|
+
labels: bug
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
A clear and concise description of what the bug is.
|
12
|
+
|
13
|
+
**To Reproduce**
|
14
|
+
Include the code for your method, class or module definition(s) where Sord is doing something incorrectly.
|
15
|
+
|
16
|
+
**Expected behavior**
|
17
|
+
A clear and concise description of what you expected to happen. It may be useful to write your own expected RBI for your code.
|
18
|
+
|
19
|
+
**Actual behavior**
|
20
|
+
A description of what actually happened. Please post any incorrectly-generated RBI signatures, as well as the command-line output of Sord.
|
21
|
+
|
22
|
+
**Additional information**
|
23
|
+
Add any other information about the problem here.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
title: ''
|
5
|
+
labels: enhancement
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
12
|
+
|
13
|
+
**Describe the solution you'd like**
|
14
|
+
A clear and concise description of what you want to happen.
|
15
|
+
|
16
|
+
**Describe alternatives you've considered**
|
17
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
18
|
+
|
19
|
+
**Additional context**
|
20
|
+
Add any other context about the feature request here.
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -99,20 +99,34 @@ class Example::Person
|
|
99
99
|
end
|
100
100
|
```
|
101
101
|
|
102
|
+
## Things to be aware of
|
103
|
+
|
104
|
+
The general rule of thumb for type conversions is:
|
105
|
+
|
106
|
+
- If Sord understands the YARD type, then it is converted into the Sorbet type.
|
107
|
+
- If the YARD type is missing, Sord fills in `T.untyped`.
|
108
|
+
- If the YARD type can't be understood, Sord creates an undefined Ruby constant
|
109
|
+
with a similar name to the unknown YARD type. For example, the obviously
|
110
|
+
invalid YARD type `A%B` will become a constant called `SORD_ERROR_AB`.
|
111
|
+
You should search through your resulting RBI to find and fix and
|
112
|
+
`SORD_ERROR`s.
|
113
|
+
|
102
114
|
## Things to work on
|
103
115
|
|
116
|
+
- No support whatsoever for blocks (they appear to cause syntax errors in RBI
|
117
|
+
currently)
|
104
118
|
- I'm not 100% sure how this handles undocumented methods and classes.
|
105
119
|
- More inference systems would be nice.
|
106
120
|
- This won't generate type parameter definitions for things which mix-in
|
107
121
|
`Enumerable`.
|
108
122
|
- Module scoping is an issue - if `Example::Person` is replaced with `Person`
|
109
123
|
in the YARD comments in the above example, Sorbet won't be able to resolve
|
110
|
-
it.
|
124
|
+
it. _This can be solved by making definitions syntactically heirarchical._
|
111
125
|
- Tests!!
|
112
126
|
|
113
127
|
## Contributing
|
114
128
|
|
115
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
129
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/AaronC81/sord. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
116
130
|
|
117
131
|
## License
|
118
132
|
|
@@ -120,4 +134,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
120
134
|
|
121
135
|
## Code of Conduct
|
122
136
|
|
123
|
-
Everyone interacting in the Sord project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
137
|
+
Everyone interacting in the Sord project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/AaronC81/sord/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/sord/rbi_generator.rb
CHANGED
@@ -59,7 +59,17 @@ module Sord
|
|
59
59
|
count_object
|
60
60
|
|
61
61
|
parameter_list = meth.parameters.map do |name, default|
|
62
|
-
|
62
|
+
# Handle these three main cases:
|
63
|
+
# - def method(param) or def method(param:)
|
64
|
+
# - def method(param: 'default')
|
65
|
+
# - def method(param = 'default')
|
66
|
+
if default.nil?
|
67
|
+
"#{name}"
|
68
|
+
elsif !default.nil? && name.end_with?(':')
|
69
|
+
"#{name} #{default}"
|
70
|
+
else
|
71
|
+
"#{name} = #{default}"
|
72
|
+
end
|
63
73
|
end.join(", ")
|
64
74
|
|
65
75
|
# This is better than iterating over YARD's "@param" tags directly
|
@@ -88,9 +98,13 @@ module Sord
|
|
88
98
|
getter.tags('return').flat_map(&:types), meth)
|
89
99
|
|
90
100
|
Logging.infer("inferred type of parameter #{name.inspect} as #{inferred_type} using getter's return type", meth)
|
101
|
+
# Get rid of : on keyword arguments.
|
102
|
+
name = name.chop if name.end_with?(':')
|
91
103
|
"#{name}: #{inferred_type}"
|
92
104
|
else
|
93
105
|
Logging.omit("no YARD type given for #{name.inspect}, using T.untyped", meth)
|
106
|
+
# Get rid of : on keyword arguments.
|
107
|
+
name = name.chop if name.end_with?(':')
|
94
108
|
"#{name}: T.untyped"
|
95
109
|
end
|
96
110
|
end.join(", ")
|
@@ -106,9 +120,10 @@ module Sord
|
|
106
120
|
|
107
121
|
prefix = meth.scope == :class ? 'self.' : ''
|
108
122
|
|
109
|
-
|
123
|
+
sig = sig_params_list.empty? ? " sig { #{returns} }" : " sig { params(#{sig_params_list}).#{returns} }"
|
124
|
+
rbi_contents << sig
|
110
125
|
|
111
|
-
rbi_contents << " def #{prefix}#{meth.name}(#{parameter_list}) end"
|
126
|
+
rbi_contents << " def #{prefix}#{meth.name}(#{parameter_list}); end"
|
112
127
|
end
|
113
128
|
end
|
114
129
|
|
@@ -154,4 +169,4 @@ module Sord
|
|
154
169
|
end
|
155
170
|
end
|
156
171
|
end
|
157
|
-
end
|
172
|
+
end
|
data/lib/sord/type_converter.rb
CHANGED
@@ -58,16 +58,22 @@ module Sord
|
|
58
58
|
# will lead to less informative log messages.
|
59
59
|
def self.yard_to_sorbet(yard, item=nil)
|
60
60
|
case yard
|
61
|
-
when nil
|
61
|
+
when nil # Type not specified
|
62
62
|
"T.untyped"
|
63
|
-
when "bool", "Bool", "boolean", "Boolean",
|
63
|
+
when "bool", "Bool", "boolean", "Boolean", "true", "false"
|
64
64
|
"T::Boolean"
|
65
|
+
when 'self'
|
66
|
+
item.parent.path
|
65
67
|
when Array
|
66
68
|
# If there's only one element, unwrap it, otherwise allow for a
|
67
69
|
# selection of any of the types
|
68
|
-
|
69
|
-
|
70
|
-
|
70
|
+
types = yard
|
71
|
+
.reject { |x| x == 'nil' }
|
72
|
+
.map { |x| yard_to_sorbet(x, item) }
|
73
|
+
.uniq
|
74
|
+
result = types.length == 1 ? types.first : "T.any(#{types.join(', ')})"
|
75
|
+
result = "T.nilable(#{result})" if yard.include?('nil')
|
76
|
+
result
|
71
77
|
when /^#{SIMPLE_TYPE_REGEX}$/
|
72
78
|
# If this doesn't begin with an uppercase letter, warn
|
73
79
|
if /^[_a-z]/ === yard
|
data/lib/sord/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Christiansen
|
@@ -130,6 +130,8 @@ executables:
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
134
|
+
- ".github/ISSUE_TEMPLATE/feature-request.md"
|
133
135
|
- ".gitignore"
|
134
136
|
- ".rspec"
|
135
137
|
- CODE_OF_CONDUCT.md
|