rbs 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +7 -1
  3. data/.gitignore +1 -1
  4. data/CHANGELOG.md +35 -0
  5. data/COPYING +1 -1
  6. data/Gemfile +16 -2
  7. data/README.md +87 -48
  8. data/Rakefile +54 -22
  9. data/bin/rbs-prof +9 -0
  10. data/bin/run_in_md.rb +49 -0
  11. data/bin/test_runner.rb +0 -2
  12. data/docs/sigs.md +6 -6
  13. data/docs/stdlib.md +3 -5
  14. data/docs/syntax.md +6 -3
  15. data/goodcheck.yml +65 -0
  16. data/lib/rbs.rb +3 -0
  17. data/lib/rbs/ast/declarations.rb +115 -14
  18. data/lib/rbs/ast/members.rb +41 -17
  19. data/lib/rbs/cli.rb +301 -123
  20. data/lib/rbs/constant.rb +4 -4
  21. data/lib/rbs/constant_table.rb +64 -53
  22. data/lib/rbs/definition.rb +175 -59
  23. data/lib/rbs/definition_builder.rb +646 -603
  24. data/lib/rbs/environment.rb +352 -210
  25. data/lib/rbs/environment_walker.rb +14 -23
  26. data/lib/rbs/errors.rb +159 -3
  27. data/lib/rbs/factory.rb +14 -0
  28. data/lib/rbs/namespace.rb +18 -0
  29. data/lib/rbs/parser.y +75 -21
  30. data/lib/rbs/prototype/rb.rb +119 -117
  31. data/lib/rbs/prototype/rbi.rb +5 -3
  32. data/lib/rbs/prototype/runtime.rb +34 -7
  33. data/lib/rbs/substitution.rb +8 -1
  34. data/lib/rbs/test.rb +81 -3
  35. data/lib/rbs/test/errors.rb +1 -1
  36. data/lib/rbs/test/hook.rb +133 -259
  37. data/lib/rbs/test/observer.rb +17 -0
  38. data/lib/rbs/test/setup.rb +13 -14
  39. data/lib/rbs/test/spy.rb +0 -321
  40. data/lib/rbs/test/tester.rb +116 -0
  41. data/lib/rbs/test/type_check.rb +44 -7
  42. data/lib/rbs/type_name_resolver.rb +58 -0
  43. data/lib/rbs/types.rb +94 -2
  44. data/lib/rbs/validator.rb +51 -0
  45. data/lib/rbs/variance_calculator.rb +12 -2
  46. data/lib/rbs/version.rb +1 -1
  47. data/lib/rbs/writer.rb +127 -91
  48. data/rbs.gemspec +0 -9
  49. data/schema/annotation.json +14 -0
  50. data/schema/comment.json +26 -0
  51. data/schema/decls.json +353 -0
  52. data/schema/function.json +87 -0
  53. data/schema/location.json +56 -0
  54. data/schema/members.json +248 -0
  55. data/schema/methodType.json +44 -0
  56. data/schema/types.json +299 -0
  57. data/stdlib/benchmark/benchmark.rbs +151 -151
  58. data/stdlib/builtin/encoding.rbs +2 -0
  59. data/stdlib/builtin/enumerable.rbs +2 -2
  60. data/stdlib/builtin/enumerator.rbs +3 -1
  61. data/stdlib/builtin/fiber.rbs +5 -1
  62. data/stdlib/builtin/file.rbs +0 -3
  63. data/stdlib/builtin/io.rbs +4 -4
  64. data/stdlib/builtin/proc.rbs +1 -2
  65. data/stdlib/builtin/symbol.rbs +1 -1
  66. data/stdlib/builtin/thread.rbs +2 -2
  67. data/stdlib/csv/csv.rbs +4 -6
  68. data/stdlib/fiber/fiber.rbs +117 -0
  69. data/stdlib/json/json.rbs +1 -1
  70. data/stdlib/logger/formatter.rbs +23 -0
  71. data/stdlib/logger/log_device.rbs +39 -0
  72. data/stdlib/logger/logger.rbs +507 -0
  73. data/stdlib/logger/period.rbs +7 -0
  74. data/stdlib/logger/severity.rbs +8 -0
  75. data/stdlib/mutex_m/mutex_m.rbs +77 -0
  76. data/stdlib/pathname/pathname.rbs +6 -6
  77. data/stdlib/prime/integer-extension.rbs +1 -1
  78. data/stdlib/prime/prime.rbs +44 -44
  79. data/stdlib/tmpdir/tmpdir.rbs +1 -1
  80. metadata +26 -116
  81. data/lib/rbs/test/test_helper.rb +0 -183
@@ -34,13 +34,4 @@ Gem::Specification.new do |spec|
34
34
  spec.bindir = "exe"
35
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
36
  spec.require_paths = ["lib"]
37
-
38
- spec.add_development_dependency "bundler"
39
- spec.add_development_dependency "rake", "~> 13.0"
40
- spec.add_development_dependency "minitest", "~> 5.0"
41
- spec.add_development_dependency "racc", "~> 1.4.16"
42
- spec.add_development_dependency "rubocop"
43
- spec.add_development_dependency "rubocop-rubycw"
44
- spec.add_development_dependency "minitest-reporters", "~> 1.3.6"
45
- spec.add_development_dependency "json", "~> 2.3.0"
46
37
  end
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Annotation associated to a declaration or a member: `%a{rbs:test}`, `%a{steep:deprecated}`, ...",
4
+ "type": "object",
5
+ "properties": {
6
+ "string": {
7
+ "type": "string"
8
+ },
9
+ "location": {
10
+ "$ref": "location.json"
11
+ }
12
+ },
13
+ "required": ["string", "location"]
14
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "definitions": {
4
+ "comment": {
5
+ "type": "object",
6
+ "properties": {
7
+ "string": {
8
+ "type": "string"
9
+ },
10
+ "location": {
11
+ "$ref": "location.json"
12
+ }
13
+ },
14
+ "required": ["string", "location"]
15
+ }
16
+ },
17
+ "title": "Comment associated with a declaration or a member",
18
+ "oneOf": [
19
+ {
20
+ "$ref": "#/definitions/comment"
21
+ },
22
+ {
23
+ "type": "null"
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1,353 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "definitions": {
4
+ "alias": {
5
+ "title": "Type alias declaration: `type foo = Integer`, ...",
6
+ "type": "object",
7
+ "properties": {
8
+ "declaration": {
9
+ "type": "string",
10
+ "enum": ["alias"]
11
+ },
12
+ "name": {
13
+ "type": "string"
14
+ },
15
+ "type": {
16
+ "$ref": "types.json"
17
+ },
18
+ "annotations": {
19
+ "type": "array",
20
+ "items": {
21
+ "$ref": "annotation.json"
22
+ }
23
+ },
24
+ "location": {
25
+ "$ref": "location.json"
26
+ },
27
+ "comment": {
28
+ "$ref": "comment.json"
29
+ }
30
+ },
31
+ "required": ["declaration", "name", "type", "annotations", "location", "comment"]
32
+ },
33
+ "constant": {
34
+ "title": "Constant declaration: `VERSION: String`, ...",
35
+ "type": "object",
36
+ "properties": {
37
+ "declaration": {
38
+ "type": "string",
39
+ "enum": ["constant"]
40
+ },
41
+ "name": {
42
+ "type": "string"
43
+ },
44
+ "type": {
45
+ "$ref": "types.json"
46
+ },
47
+ "location": {
48
+ "$ref": "location.json"
49
+ },
50
+ "comment": {
51
+ "$ref": "comment.json"
52
+ }
53
+ },
54
+ "required": ["declaration", "name", "type", "comment", "location"]
55
+ },
56
+ "global": {
57
+ "title": "Global declaration: `$DEBUG: bool`, ...",
58
+ "type": "object",
59
+ "properties": {
60
+ "declaration": {
61
+ "type": "string",
62
+ "enum": ["global"]
63
+ },
64
+ "name": {
65
+ "type": "string"
66
+ },
67
+ "type": {
68
+ "$ref": "types.json"
69
+ },
70
+ "location": {
71
+ "$ref": "location.json"
72
+ },
73
+ "comment": {
74
+ "$ref": "comment.json"
75
+ }
76
+ },
77
+ "required": ["declaration", "name", "type", "comment", "location"]
78
+ },
79
+ "moduleTypeParam": {
80
+ "type": "object",
81
+ "properties": {
82
+ "name": {
83
+ "type": "string"
84
+ },
85
+ "variance": {
86
+ "enum": ["covariant", "contravariant", "invariant"]
87
+ },
88
+ "skip_validation": {
89
+ "type": "boolean"
90
+ }
91
+ },
92
+ "required": ["name", "variance", "skip_validation"]
93
+ },
94
+ "classMember": {
95
+ "oneOf": [
96
+ {
97
+ "$ref": "members.json#/definitions/methodDefinition"
98
+ },
99
+ {
100
+ "$ref": "members.json#/definitions/variable"
101
+ },
102
+ {
103
+ "$ref": "members.json#/definitions/include"
104
+ },
105
+ {
106
+ "$ref": "members.json#/definitions/extend"
107
+ },
108
+ {
109
+ "$ref": "members.json#/definitions/prepend"
110
+ },
111
+ {
112
+ "$ref": "members.json#/definitions/attribute"
113
+ },
114
+ {
115
+ "$ref": "members.json#/definitions/visibility"
116
+ },
117
+ {
118
+ "$ref": "members.json#/definitions/alias"
119
+ },
120
+ {
121
+ "$ref": "#/definitions/alias"
122
+ },
123
+ {
124
+ "$ref": "#/definitions/constant"
125
+ },
126
+ {
127
+ "$ref": "#/definitions/class"
128
+ },
129
+ {
130
+ "$ref": "#/definitions/module"
131
+ },
132
+ {
133
+ "$ref": "#/definitions/interface"
134
+ }
135
+ ]
136
+ },
137
+ "class": {
138
+ "title": "Class declaration",
139
+ "type": "object",
140
+ "properties": {
141
+ "declaration": {
142
+ "enum": ["class"]
143
+ },
144
+ "name": {
145
+ "type": "string"
146
+ },
147
+ "type_params": {
148
+ "type": "object",
149
+ "properties": {
150
+ "params": {
151
+ "type": "array",
152
+ "items": {
153
+ "$ref": "#/definitions/moduleTypeParam"
154
+ }
155
+ }
156
+ },
157
+ "required": ["params"]
158
+ },
159
+ "members": {
160
+ "type": "array",
161
+ "items": {
162
+ "$ref": "#/definitions/classMember"
163
+ }
164
+ },
165
+ "super_class": {
166
+ "oneOf": [
167
+ {
168
+ "type": "null"
169
+ },
170
+ {
171
+ "type": "object",
172
+ "properties": {
173
+ "name": {
174
+ "type": "string"
175
+ },
176
+ "args": {
177
+ "type": "array",
178
+ "items": {
179
+ "$ref": "types.json"
180
+ }
181
+ }
182
+ },
183
+ "required": ["name", "args"]
184
+ }
185
+ ]
186
+ },
187
+ "annotations": {
188
+ "type": "array",
189
+ "items": {
190
+ "$ref": "annotation.json"
191
+ }
192
+ },
193
+ "comment": {
194
+ "$ref": "comment.json"
195
+ },
196
+ "location": {
197
+ "$ref": "location.json"
198
+ }
199
+ },
200
+ "required": ["declaration", "name", "type_params", "members", "super_class", "annotations", "comment", "location"]
201
+ },
202
+ "module": {
203
+ "type": "object",
204
+ "properties": {
205
+ "declaration": {
206
+ "enum": ["module"]
207
+ },
208
+ "name": {
209
+ "type": "string"
210
+ },
211
+ "type_params": {
212
+ "type": "object",
213
+ "properties": {
214
+ "params": {
215
+ "type": "array",
216
+ "items": {
217
+ "$ref": "#/definitions/moduleTypeParam"
218
+ }
219
+ }
220
+ },
221
+ "required": ["params"]
222
+ },
223
+ "members": {
224
+ "type": "array",
225
+ "items": {
226
+ "$ref": "#/definitions/classMember"
227
+ }
228
+ },
229
+ "self_types": {
230
+ "type": "array",
231
+ "items": {
232
+ "$ref": "#/definitions/moduleSelf"
233
+ }
234
+ },
235
+ "annotations": {
236
+ "type": "array",
237
+ "items": {
238
+ "$ref": "annotation.json"
239
+ }
240
+ },
241
+ "comment": {
242
+ "$ref": "comment.json"
243
+ },
244
+ "location": {
245
+ "$ref": "location.json"
246
+ }
247
+ },
248
+ "required": ["declaration", "name", "type_params", "members", "self_types", "annotations", "location", "comment"]
249
+ },
250
+ "moduleSelf": {
251
+ "type": "object",
252
+ "properties": {
253
+ "name": {
254
+ "type": "string"
255
+ },
256
+ "args": {
257
+ "type": "array",
258
+ "items": {
259
+ "$ref": "types.json"
260
+ }
261
+ }
262
+ },
263
+ "required": ["name", "args"]
264
+ },
265
+ "interfaceMember": {
266
+ "oneOf": [
267
+ {
268
+ "allOf": [
269
+ {
270
+ "$ref": "members.json#/definitions/methodDefinition"
271
+ },
272
+ {
273
+ "type": "object",
274
+ "properties": {
275
+ "kind": {
276
+ "enum": ["instance"]
277
+ }
278
+ }
279
+ }
280
+ ]
281
+ },
282
+ {
283
+ "$ref": "members.json#/definitions/include"
284
+ },
285
+ {
286
+ "$ref": "members.json#/definitions/alias"
287
+ }
288
+ ]
289
+ },
290
+ "interface": {
291
+ "type": "object",
292
+ "properties": {
293
+ "declaration": {
294
+ "enum": ["interface"]
295
+ },
296
+ "name": {
297
+ "type": "string"
298
+ },
299
+ "type_params": {
300
+ "type": "object",
301
+ "properties": {
302
+ "params": {
303
+ "type": "array",
304
+ "items": {
305
+ "$ref": "#/definitions/moduleTypeParam"
306
+ }
307
+ }
308
+ },
309
+ "required": ["params"]
310
+ },
311
+ "members": {
312
+ "type": "array",
313
+ "items": {
314
+ "$ref": "#/definitions/interfaceMember"
315
+ }
316
+ },
317
+ "annotations": {
318
+ "type": "array",
319
+ "items": {
320
+ "$ref": "annotation.json"
321
+ }
322
+ },
323
+ "comment": {
324
+ "$ref": "comment.json"
325
+ },
326
+ "location": {
327
+ "$ref": "location.json"
328
+ }
329
+ },
330
+ "required": ["declaration", "name", "type_params", "members", "annotations", "comment", "location"]
331
+ }
332
+ },
333
+ "oneOf": [
334
+ {
335
+ "$ref": "#/definitions/alias"
336
+ },
337
+ {
338
+ "$ref": "#/definitions/constant"
339
+ },
340
+ {
341
+ "$ref": "#/definitions/global"
342
+ },
343
+ {
344
+ "$ref": "#/definitions/class"
345
+ },
346
+ {
347
+ "$ref": "#/definitions/module"
348
+ },
349
+ {
350
+ "$ref": "#/definitions/interface"
351
+ }
352
+ ]
353
+ }
@@ -0,0 +1,87 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "definitions": {
4
+ "param": {
5
+ "title": "Function parameter with type and optional name: `Integer size`, `::String name`, `untyped`, ...",
6
+ "type": "object",
7
+ "properties": {
8
+ "type": {
9
+ "$ref": "types.json"
10
+ },
11
+ "name": {
12
+ "oneOf": [
13
+ {
14
+ "type": "string"
15
+ },
16
+ {
17
+ "type": "null"
18
+ }
19
+ ]
20
+ }
21
+ },
22
+ "required": ["type", "name"]
23
+ }
24
+ },
25
+ "properties": {
26
+ "required_positionals": {
27
+ "title": "Required positional parameters",
28
+ "type": "array",
29
+ "items": {
30
+ "$ref": "#/definitions/param"
31
+ }
32
+ },
33
+ "optional_positionals": {
34
+ "title": "Optional positional parameters",
35
+ "type": "array",
36
+ "items": {
37
+ "$ref": "#/definitions/param"
38
+ }
39
+ },
40
+ "rest_positionals": {
41
+ "title": "Rest parameter",
42
+ "oneOf": [
43
+ {
44
+ "$ref": "#/definitions/param"
45
+ },
46
+ {
47
+ "type": "null"
48
+ }
49
+ ]
50
+ },
51
+ "trailing_positionals": {
52
+ "title": "Trailing potisional parameters",
53
+ "type": "array",
54
+ "items": {
55
+ "$ref": "#/definitions/param"
56
+ }
57
+ },
58
+ "required_keywords": {
59
+ "title": "Required keyword parameters",
60
+ "additionalProperties": {
61
+ "$ref": "#/definitions/param"
62
+ }
63
+ },
64
+ "optional_keywords": {
65
+ "title": "Optional keyword parameters",
66
+ "additionalProperties": {
67
+ "$ref": "#/definitions/param"
68
+ }
69
+ },
70
+ "rest_keywords": {
71
+ "title": "Rest keyword parameters",
72
+ "oneOf": [
73
+ {
74
+ "$ref": "#/definitions/param"
75
+ },
76
+ {
77
+ "type": "null"
78
+ }
79
+ ]
80
+ },
81
+ "return_type": {
82
+ "title": "Return type of a function",
83
+ "$ref": "types.json"
84
+ }
85
+ },
86
+ "required": ["required_positionals", "optional_positionals", "rest_positionals", "trailing_positionals", "required_keywords", "optional_keywords", "rest_keywords", "return_type"]
87
+ }