steep 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (299) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +27 -0
  3. data/.gitmodules +3 -0
  4. data/CHANGELOG.md +5 -0
  5. data/README.md +48 -90
  6. data/Rakefile +10 -6
  7. data/Steepfile +1 -0
  8. data/bin/setup +1 -0
  9. data/bin/smoke_runner.rb +9 -14
  10. data/exe/rbs +3 -0
  11. data/exe/ruby-signature +3 -0
  12. data/exe/steep +1 -0
  13. data/lib/steep.rb +32 -26
  14. data/lib/steep/annotation_parser.rb +167 -0
  15. data/lib/steep/ast/annotation/collection.rb +7 -7
  16. data/lib/steep/ast/types.rb +60 -0
  17. data/lib/steep/ast/types/any.rb +1 -1
  18. data/lib/steep/ast/types/factory.rb +535 -0
  19. data/lib/steep/ast/types/name.rb +3 -3
  20. data/lib/steep/ast/types/var.rb +1 -1
  21. data/lib/steep/cli.rb +56 -240
  22. data/lib/steep/drivers/annotations.rb +36 -19
  23. data/lib/steep/drivers/check.rb +55 -91
  24. data/lib/steep/drivers/init.rb +54 -0
  25. data/lib/steep/drivers/langserver.rb +241 -150
  26. data/lib/steep/drivers/print_project.rb +56 -0
  27. data/lib/steep/drivers/signature_error_printer.rb +25 -0
  28. data/lib/steep/drivers/trace_printer.rb +25 -0
  29. data/lib/steep/drivers/utils/driver_helper.rb +26 -0
  30. data/lib/steep/drivers/validate.rb +18 -38
  31. data/lib/steep/drivers/vendor.rb +46 -0
  32. data/lib/steep/drivers/watch.rb +78 -140
  33. data/lib/steep/errors.rb +22 -13
  34. data/lib/steep/interface/interface.rb +91 -0
  35. data/lib/steep/interface/method.rb +0 -4
  36. data/lib/steep/interface/method_type.rb +362 -2
  37. data/lib/steep/interface/substitution.rb +22 -0
  38. data/lib/steep/project.rb +25 -233
  39. data/lib/steep/project/dsl.rb +132 -0
  40. data/lib/steep/project/file.rb +93 -76
  41. data/lib/steep/project/file_loader.rb +63 -0
  42. data/lib/steep/project/options.rb +7 -0
  43. data/lib/steep/project/target.rb +190 -0
  44. data/lib/steep/signature/errors.rb +25 -77
  45. data/lib/steep/signature/validator.rb +122 -0
  46. data/lib/steep/source.rb +12 -7
  47. data/lib/steep/subtyping/check.rb +357 -633
  48. data/lib/steep/subtyping/constraints.rb +2 -2
  49. data/lib/steep/subtyping/trace.rb +23 -0
  50. data/lib/steep/type_construction.rb +509 -455
  51. data/lib/steep/type_inference/constant_env.rb +16 -24
  52. data/lib/steep/type_inference/type_env.rb +26 -18
  53. data/lib/steep/version.rb +1 -1
  54. data/sample/Steepfile +6 -0
  55. data/sample/lib/conference.rb +12 -0
  56. data/sample/sig/conference.rbs +6 -0
  57. data/smoke/alias/Steepfile +4 -0
  58. data/smoke/alias/a.rb +2 -2
  59. data/smoke/alias/{a.rbi → a.rbs} +1 -1
  60. data/smoke/and/Steepfile +4 -0
  61. data/smoke/array/Steepfile +4 -0
  62. data/smoke/array/a.rb +2 -2
  63. data/smoke/array/b.rb +4 -4
  64. data/smoke/array/c.rb +2 -2
  65. data/smoke/block/Steepfile +5 -0
  66. data/smoke/block/{a.rbi → a.rbs} +1 -1
  67. data/smoke/block/{c.rbi → c.rbs} +0 -0
  68. data/smoke/block/d.rb +6 -6
  69. data/smoke/case/Steepfile +4 -0
  70. data/smoke/case/a.rb +4 -3
  71. data/smoke/class/Steepfile +4 -0
  72. data/smoke/class/a.rb +1 -4
  73. data/smoke/class/a.rbs +24 -0
  74. data/smoke/class/h.rb +6 -2
  75. data/smoke/class/{h.rbi → h.rbs} +1 -2
  76. data/smoke/class/i.rb +1 -2
  77. data/smoke/class/i.rbs +9 -0
  78. data/smoke/const/Steepfile +4 -0
  79. data/smoke/dstr/Steepfile +4 -0
  80. data/smoke/ensure/Steepfile +4 -0
  81. data/smoke/ensure/a.rb +1 -1
  82. data/smoke/enumerator/Steepfile +4 -0
  83. data/smoke/enumerator/a.rb +7 -7
  84. data/smoke/enumerator/b.rb +6 -6
  85. data/smoke/extension/Steepfile +4 -0
  86. data/smoke/extension/{a.rbi → a.rbs} +2 -2
  87. data/smoke/extension/{e.rbi → e.rbs} +2 -2
  88. data/smoke/hash/Steepfile +4 -0
  89. data/smoke/hash/{a.rbi → a.rbs} +0 -0
  90. data/smoke/hash/b.rb +2 -2
  91. data/smoke/hash/c.rb +1 -1
  92. data/smoke/hash/e.rbs +3 -0
  93. data/smoke/hash/f.rb +1 -1
  94. data/smoke/hello/Steepfile +4 -0
  95. data/smoke/hello/hello.rbs +7 -0
  96. data/smoke/if/Steepfile +4 -0
  97. data/smoke/implements/Steepfile +4 -0
  98. data/smoke/implements/a.rbs +6 -0
  99. data/smoke/initialize/Steepfile +4 -0
  100. data/smoke/initialize/a.rbs +3 -0
  101. data/smoke/integer/Steepfile +4 -0
  102. data/smoke/integer/a.rb +5 -3
  103. data/smoke/interface/Steepfile +4 -0
  104. data/smoke/interface/{a.rbi → a.rbs} +0 -0
  105. data/smoke/kwbegin/Steepfile +4 -0
  106. data/smoke/lambda/Steepfile +4 -0
  107. data/smoke/lambda/a.rb +9 -2
  108. data/smoke/literal/Steepfile +4 -0
  109. data/smoke/literal/{literal_methods.rbi → literal_methods.rbs} +0 -0
  110. data/smoke/map/Steepfile +4 -0
  111. data/smoke/map/a.rb +1 -1
  112. data/smoke/method/Steepfile +4 -0
  113. data/smoke/method/{a.rbi → a.rbs} +0 -0
  114. data/smoke/method/b.rb +1 -4
  115. data/smoke/method/d.rb +1 -0
  116. data/smoke/method/d.rbs +3 -0
  117. data/smoke/module/Steepfile +4 -0
  118. data/smoke/module/a.rb +1 -1
  119. data/smoke/module/a.rbs +16 -0
  120. data/smoke/module/c.rb +1 -1
  121. data/smoke/regexp/Steepfile +4 -0
  122. data/smoke/regexp/a.rb +2 -2
  123. data/smoke/regexp/b.rb +16 -16
  124. data/smoke/regression/Steepfile +5 -0
  125. data/smoke/regression/array.rb +2 -2
  126. data/smoke/regression/hash.rb +2 -2
  127. data/smoke/regression/poly_new.rb +2 -0
  128. data/smoke/regression/poly_new.rbs +4 -0
  129. data/smoke/regression/set_divide.rb +2 -2
  130. data/smoke/rescue/Steepfile +4 -0
  131. data/smoke/rescue/a.rb +1 -1
  132. data/smoke/self/Steepfile +4 -0
  133. data/smoke/self/a.rbs +4 -0
  134. data/smoke/skip/Steepfile +4 -0
  135. data/smoke/stdout/Steepfile +4 -0
  136. data/smoke/stdout/{a.rbi → a.rbs} +1 -1
  137. data/smoke/super/Steepfile +4 -0
  138. data/smoke/super/a.rbs +10 -0
  139. data/smoke/type_case/Steepfile +4 -0
  140. data/smoke/type_case/a.rb +1 -1
  141. data/smoke/yield/Steepfile +4 -0
  142. data/smoke/yield/a.rb +2 -2
  143. data/steep.gemspec +14 -7
  144. data/vendor/ruby-signature/.github/workflows/ruby.yml +27 -0
  145. data/vendor/ruby-signature/.gitignore +12 -0
  146. data/vendor/ruby-signature/.rubocop.yml +15 -0
  147. data/vendor/ruby-signature/BSDL +22 -0
  148. data/vendor/ruby-signature/COPYING +56 -0
  149. data/vendor/ruby-signature/Gemfile +6 -0
  150. data/vendor/ruby-signature/README.md +93 -0
  151. data/vendor/ruby-signature/Rakefile +66 -0
  152. data/vendor/ruby-signature/bin/annotate-with-rdoc +156 -0
  153. data/vendor/ruby-signature/bin/console +14 -0
  154. data/vendor/ruby-signature/bin/query-rdoc +103 -0
  155. data/vendor/ruby-signature/bin/setup +10 -0
  156. data/vendor/ruby-signature/bin/sort +88 -0
  157. data/vendor/ruby-signature/bin/test_runner.rb +17 -0
  158. data/vendor/ruby-signature/docs/CONTRIBUTING.md +97 -0
  159. data/vendor/ruby-signature/docs/sigs.md +148 -0
  160. data/vendor/ruby-signature/docs/stdlib.md +152 -0
  161. data/vendor/ruby-signature/docs/syntax.md +528 -0
  162. data/vendor/ruby-signature/exe/rbs +3 -0
  163. data/vendor/ruby-signature/exe/ruby-signature +7 -0
  164. data/vendor/ruby-signature/lib/ruby/signature.rb +64 -0
  165. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +29 -0
  166. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +29 -0
  167. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +391 -0
  168. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +364 -0
  169. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +52 -0
  170. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +54 -0
  171. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +534 -0
  172. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +28 -0
  173. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +152 -0
  174. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +172 -0
  175. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +921 -0
  176. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +283 -0
  177. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +138 -0
  178. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +126 -0
  179. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +189 -0
  180. data/vendor/ruby-signature/lib/ruby/signature/location.rb +104 -0
  181. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +125 -0
  182. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +93 -0
  183. data/vendor/ruby-signature/lib/ruby/signature/parser.y +1343 -0
  184. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +441 -0
  185. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +579 -0
  186. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +383 -0
  187. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +48 -0
  188. data/vendor/ruby-signature/lib/ruby/signature/test.rb +28 -0
  189. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +63 -0
  190. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +290 -0
  191. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +58 -0
  192. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +324 -0
  193. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +185 -0
  194. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +256 -0
  195. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +72 -0
  196. data/vendor/ruby-signature/lib/ruby/signature/types.rb +932 -0
  197. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +140 -0
  198. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +49 -0
  199. data/vendor/ruby-signature/lib/ruby/signature/version.rb +5 -0
  200. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +271 -0
  201. data/vendor/ruby-signature/ruby-signature.gemspec +45 -0
  202. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +3 -0
  203. data/vendor/ruby-signature/stdlib/base64/base64.rbs +15 -0
  204. data/vendor/ruby-signature/stdlib/builtin/array.rbs +1997 -0
  205. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +280 -0
  206. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +177 -0
  207. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +35 -0
  208. data/vendor/ruby-signature/stdlib/builtin/class.rbs +145 -0
  209. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +116 -0
  210. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +400 -0
  211. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +37 -0
  212. data/vendor/ruby-signature/stdlib/builtin/data.rbs +5 -0
  213. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +2 -0
  214. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +419 -0
  215. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +606 -0
  216. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +404 -0
  217. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +260 -0
  218. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +781 -0
  219. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +582 -0
  220. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +193 -0
  221. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +40 -0
  222. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +68 -0
  223. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +12 -0
  224. data/vendor/ruby-signature/stdlib/builtin/file.rbs +476 -0
  225. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +59 -0
  226. data/vendor/ruby-signature/stdlib/builtin/float.rbs +696 -0
  227. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +121 -0
  228. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +1029 -0
  229. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +710 -0
  230. data/vendor/ruby-signature/stdlib/builtin/io.rbs +683 -0
  231. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +574 -0
  232. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +135 -0
  233. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +141 -0
  234. data/vendor/ruby-signature/stdlib/builtin/math.rbs +66 -0
  235. data/vendor/ruby-signature/stdlib/builtin/method.rbs +182 -0
  236. data/vendor/ruby-signature/stdlib/builtin/module.rbs +248 -0
  237. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +82 -0
  238. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +409 -0
  239. data/vendor/ruby-signature/stdlib/builtin/object.rbs +824 -0
  240. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +426 -0
  241. data/vendor/ruby-signature/stdlib/builtin/process.rbs +354 -0
  242. data/vendor/ruby-signature/stdlib/builtin/random.rbs +93 -0
  243. data/vendor/ruby-signature/stdlib/builtin/range.rbs +226 -0
  244. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +424 -0
  245. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +10 -0
  246. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +131 -0
  247. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +14 -0
  248. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +55 -0
  249. data/vendor/ruby-signature/stdlib/builtin/string.rbs +770 -0
  250. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +13 -0
  251. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +40 -0
  252. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +230 -0
  253. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +1112 -0
  254. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +23 -0
  255. data/vendor/ruby-signature/stdlib/builtin/time.rbs +739 -0
  256. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +91 -0
  257. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +46 -0
  258. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +159 -0
  259. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +17 -0
  260. data/vendor/ruby-signature/stdlib/erb/erb.rbs +18 -0
  261. data/vendor/ruby-signature/stdlib/find/find.rbs +44 -0
  262. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +21 -0
  263. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +23 -0
  264. data/vendor/ruby-signature/stdlib/prime/prime.rbs +188 -0
  265. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +9 -0
  266. data/vendor/ruby-signature/stdlib/set/set.rbs +77 -0
  267. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +53 -0
  268. metadata +244 -54
  269. data/.travis.yml +0 -7
  270. data/lib/steep/ast/signature/alias.rb +0 -19
  271. data/lib/steep/ast/signature/class.rb +0 -33
  272. data/lib/steep/ast/signature/const.rb +0 -17
  273. data/lib/steep/ast/signature/env.rb +0 -138
  274. data/lib/steep/ast/signature/extension.rb +0 -21
  275. data/lib/steep/ast/signature/gvar.rb +0 -17
  276. data/lib/steep/ast/signature/interface.rb +0 -31
  277. data/lib/steep/ast/signature/members.rb +0 -115
  278. data/lib/steep/ast/signature/module.rb +0 -21
  279. data/lib/steep/drivers/print_interface.rb +0 -94
  280. data/lib/steep/drivers/scaffold.rb +0 -321
  281. data/lib/steep/drivers/utils/each_signature.rb +0 -31
  282. data/lib/steep/interface/abstract.rb +0 -68
  283. data/lib/steep/interface/builder.rb +0 -637
  284. data/lib/steep/interface/instantiated.rb +0 -163
  285. data/lib/steep/interface/ivar_chain.rb +0 -26
  286. data/lib/steep/parser.y +0 -1278
  287. data/lib/steep/project/listener.rb +0 -53
  288. data/smoke/class/a.rbi +0 -24
  289. data/smoke/class/d.rb +0 -9
  290. data/smoke/class/e.rb +0 -12
  291. data/smoke/class/i.rbi +0 -9
  292. data/smoke/hash/e.rbi +0 -3
  293. data/smoke/hello/hello.rbi +0 -7
  294. data/smoke/implements/a.rbi +0 -6
  295. data/smoke/initialize/a.rbi +0 -3
  296. data/smoke/module/a.rbi +0 -16
  297. data/smoke/self/a.rbi +0 -4
  298. data/smoke/super/a.rbi +0 -10
  299. data/stdlib/builtin.rbi +0 -787
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30d4bfab06e5fe0027f3e2cd8d7570fa5b887d7c4ac177c6cfed0003d71f77b7
4
- data.tar.gz: ab030947cb032f0fcbb3e9ca7febf38ad489ee4ab21a4a798fb620e9db807ead
3
+ metadata.gz: b3a5b5a55253f50083410cd7d58bf7cda545301d9a7d5b72a5a8fd3865a76e93
4
+ data.tar.gz: fcf1273fc81c720266d4cdf2456d996b8f406137b204bb22fe1ad25852850a0a
5
5
  SHA512:
6
- metadata.gz: cec192c40e6de3ea830b3aa6c2f2cdb619b00af8a75c2a754f8302f94423c7f9f098b3e48e44568c967c38c4f34da19309b74999c8efe5e7636e4714375b9c59
7
- data.tar.gz: b39f4f9f986b70426c5f0738840222f9a8241a4bf42df04d2aa17388f2d6a69014e91442a3021fbc8c1f269cf94361b0786a83d5b61e4557af36e773c7ad66d3
6
+ metadata.gz: a6e6dc76cf7aaf2cdf97965733d6762a1fb75d314d0dd8f859cc617296a433a002a512c829828a927bc43718e2f44776332f1c739d894460d8828195853a24c9
7
+ data.tar.gz: c3daca75b0a4846302665a9d165f13de175e1e5436d3605fa5c53948bc5548b1a36a19a43e4200d4f3b37ce257e8369ec645602ccb15b419b5fae0f1c34e39b1
@@ -0,0 +1,27 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request: {}
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: "ubuntu-latest"
12
+ strategy:
13
+ matrix:
14
+ container_tag:
15
+ - 2.6.5-bionic
16
+ - 2.7.0-bionic
17
+ container:
18
+ image: rubylang/ruby:${{ matrix.container_tag }}
19
+ steps:
20
+ - uses: actions/checkout@v1
21
+ - name: Run test
22
+ run: |
23
+ ruby -v
24
+ gem install bundler
25
+ bundle install --jobs 4 --retry 3
26
+ bin/setup
27
+ bundle exec rake build test smoke
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "vendor/ruby-signature"]
2
+ path = vendor/ruby-signature
3
+ url = https://github.com/ruby/ruby-signature.git
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.12.0 (2020-02-11)
6
+
7
+ * Add `Steepfile` for configuration
8
+ * Use the latest version of `ruby-signature`
9
+
5
10
  ## 0.11.1 (2019-07-15)
6
11
 
7
12
  * Relax activesupport versnion requirement (#90)
data/README.md CHANGED
@@ -8,32 +8,51 @@ Install via RubyGems.
8
8
 
9
9
  ### Requirements
10
10
 
11
- Steep requires Ruby 2.5.
11
+ Steep requires Ruby 2.6.
12
12
 
13
13
  ## Usage
14
14
 
15
15
  Steep does not infer types from Ruby programs, but requires declaring types and writing annotations.
16
16
  You have to go on the following three steps.
17
17
 
18
+ ### 0. `steep init`
19
+
20
+ Run `steep init` to generate a configuration file.
21
+
22
+ ```
23
+ $ steep init # Generates Steepfile
24
+ ```
25
+
26
+ Edit the `Steepfile`:
27
+
28
+ ```rb
29
+ target :app do
30
+ check "lib"
31
+ signature "sig"
32
+
33
+ library "set", "pathname"
34
+ end
35
+ ```
36
+
18
37
  ### 1. Declare Types
19
38
 
20
- Declare types in `.rbi` files in `sig` directory.
39
+ Declare types in `.rbs` files in `sig` directory.
21
40
 
22
41
  ```
23
42
  class Person
24
43
  @name: String
25
- @contacts: Array<Email | Phone>
44
+ @contacts: Array[Email | Phone]
26
45
 
27
- def initialize: (name: String) -> any
46
+ def initialize: (name: String) -> untyped
28
47
  def name: -> String
29
- def contacts: -> Array<Email | Phone>
48
+ def contacts: -> Array[Email | Phone]
30
49
  def guess_country: -> (String | nil)
31
50
  end
32
51
 
33
52
  class Email
34
53
  @address: String
35
54
 
36
- def initialize: (address: String) -> any
55
+ def initialize: (address: String) -> untyped
37
56
  def address: -> String
38
57
  end
39
58
 
@@ -41,15 +60,15 @@ class Phone
41
60
  @country: String
42
61
  @number: String
43
62
 
44
- def initialize: (country: String, number: String) -> any
63
+ def initialize: (country: String, number: String) -> untyped
45
64
  def country: -> String
46
65
  def number: -> String
47
66
 
48
- def self.countries: -> Hash<String, String>
67
+ def self.countries: -> Hash[String, String]
49
68
  end
50
69
  ```
51
70
 
52
- * You can use simple *generics*, like `Hash<String, String>`.
71
+ * You can use simple *generics*, like `Hash[String, String]`.
53
72
  * You can use *union types*, like `Email | Phone`.
54
73
  * You have to declare not only public methods but also private methods and instance variables.
55
74
  * You can declare *singleton methods*, like `self.countries`.
@@ -95,7 +114,7 @@ class Email
95
114
  end
96
115
 
97
116
  def ==(other)
98
- # `other` has type of `any`, which means type checking is skipped.
117
+ # `other` has type of `untyped`, which means type checking is skipped.
99
118
  # No type errors can be detected in this method.
100
119
  other.is_a?(self.class) && other.address == address
101
120
  end
@@ -114,7 +133,7 @@ class Phone
114
133
  end
115
134
 
116
135
  def ==(other)
117
- # You cannot use `case` for type case because `other` has type of `any`, not a union type.
136
+ # You cannot use `case` for type case because `other` has type of `untyped`, not a union type.
118
137
  # You have to explicitly declare the type of `other` in `if` expression.
119
138
 
120
139
  if other.is_a?(Phone)
@@ -134,38 +153,38 @@ end
134
153
  Run `steep check` command to type check. 💡
135
154
 
136
155
  ```
137
- $ steep check lib
156
+ $ steep check
138
157
  lib/phone.rb:46:0: MethodDefinitionMissing: module=::Phone, method=self.countries (class Phone)
139
158
  ```
140
159
 
141
160
  You now find `Phone.countries` method is not implemented yet. 🙃
142
161
 
143
- ## Scaffolding
162
+ ## Prototyping signature
144
163
 
145
- You can use `steep scaffold` command to generate a signature declaration.
164
+ You can use `rbs prototype` command to generate a signature declaration.
146
165
 
147
166
  ```
148
- $ steep scaffold lib/*.rb
167
+ $ rbs prototype rb lib/person.rb lib/email.rb lib/phone.rb
149
168
  class Person
150
- @name: any
151
- @contacts: Array<any>
152
- def initialize: (name: any) -> Array<any>
153
- def guess_country: () -> any
169
+ @name: untyped
170
+ @contacts: Array[untyped]
171
+ def initialize: (name: untyped) -> Array[untyped]
172
+ def guess_country: () -> untyped
154
173
  end
155
174
 
156
175
  class Email
157
- @address: any
158
- def initialize: (address: any) -> any
159
- def ==: (any) -> any
160
- def hash: () -> any
176
+ @address: untyped
177
+ def initialize: (address: untyped) -> untyped
178
+ def ==: (untyped) -> untyped
179
+ def hash: () -> untyped
161
180
  end
162
181
 
163
182
  class Phone
164
- @country: any
165
- @number: any
166
- def initialize: (country: any, number: any) -> any
167
- def ==: (any) -> void
168
- def hash: () -> any
183
+ @country: untyped
184
+ @number: untyped
185
+ def initialize: (country: untyped, number: untyped) -> untyped
186
+ def ==: (untyped) -> void
187
+ def hash: () -> untyped
169
188
  end
170
189
  ```
171
190
 
@@ -179,68 +198,7 @@ Because it just prints all `def`s, you may find some odd points:
179
198
 
180
199
  Generally, these are by our design.
181
200
 
182
- ## Commandline
183
-
184
- `steep check` is the command to run type checking.
185
-
186
- ### Signature Directory
187
-
188
- Use `-I` option to specify signature file or signature directory.
189
-
190
- $ steep check -I my-types.rbi test.rb
191
-
192
- If you don't specify `-I` option, it assumes `sig` directory.
193
-
194
- ### Detecting Fallback
195
-
196
- When Steep finds an expression which cannot be typed, it assumes the type of the node is *any*.
197
- *any* type does not raise any type error so that fallback to *any* may hide some type errors.
198
-
199
- Using `--fallback-any-is-error` option prints the fallbacks.
200
-
201
- $ steep check --fallback-any-is-error test.rb
202
-
203
- ### Dump All Types
204
-
205
- When you are debugging, printing all types of all node in the source code may help.
206
-
207
- Use `--dump-all-types` for that.
208
-
209
- $ steep check --dump-all-types test.rb
210
-
211
- ### Verbose Option
212
-
213
- Try `-v` option to report more information about type checking.
214
-
215
- ### Loading Type definitions from Gems
216
-
217
- You can pass `-G` option to specify name of gems to load type definitions.
218
-
219
- ```
220
- $ steep check -G strong_json lib
221
- ```
222
-
223
- When you are using bundler, Steep load type definitions from bundled gems automatically.
224
-
225
- ```
226
- $ bundle exec steep check lib
227
- ```
228
-
229
- To disable automatic gem detection from bundler, you can specify `--no-bundler` option.
230
-
231
- ```
232
- $ bundle exec steep check --no-bundler -G strong_json lib
233
- ```
234
-
235
- ## Making a Gem with Type Definition
236
-
237
- Put your type definition file in a directory, ship that in your gem, and let `metadata` of the gemspec to contain `"steep_types" => dir_name`.
238
-
239
- ```rb
240
- spec.metadata = { "steep_types" => "sig" }
241
- ```
242
-
243
- We recommend using `sig` as a name of the directory for type definitions, but you can use any directory.
201
+ `rbs prototype` offers options: `rbi` to generate prototype from Sorbet RBI and `runtime` to generate from runtime API.
244
202
 
245
203
  ## Examples
246
204
 
data/Rakefile CHANGED
@@ -8,15 +8,19 @@ Rake::TestTask.new(:test) do |t|
8
8
  end
9
9
 
10
10
  task :default => :test
11
- task :build => :racc
12
- task :test => :racc
13
- task :install => :racc
11
+ task :build => :parser
12
+ task :test => :parser
13
+ task :install => [:reset, :parser]
14
14
 
15
- rule /\.rb/ => ".y" do |t|
16
- sh "racc", "-v", "-o", "#{t.name}", "#{t.source}"
15
+ task :parser do
16
+ Dir.chdir "vendor/ruby-signature" do
17
+ sh "bundle exec rake parser"
18
+ end
17
19
  end
18
20
 
19
- task :racc => "lib/steep/parser.rb"
21
+ task :reset do
22
+ sh "git submodule update -f --init"
23
+ end
20
24
 
21
25
  task :smoke do
22
26
  sh "bundle", "exec", "bin/smoke_runner.rb", *Dir.glob("smoke/*")
data/Steepfile ADDED
@@ -0,0 +1 @@
1
+ target :app do end
data/bin/setup CHANGED
@@ -6,3 +6,4 @@ set -vx
6
6
  bundle install
7
7
 
8
8
  # Do any other automated setup that you need to do here
9
+ bundle exec rake reset parser
data/bin/smoke_runner.rb CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  require "pathname"
4
4
 
5
+ $LOAD_PATH << Pathname(__dir__) + '../vendor/ruby-signature/lib'
5
6
  $LOAD_PATH << Pathname(__dir__) + "../lib"
6
7
 
7
8
  require "steep"
9
+ require "steep/cli"
8
10
  require "rainbow"
9
11
  require "optparse"
10
12
 
@@ -44,7 +46,7 @@ ARGV.each do |arg|
44
46
  message = src.gsub!(/\A!expects\*(@\+\d+)? +/, '')
45
47
  line = comment.location.line
46
48
 
47
- expectations << Expectation.new(line+offset, message, file).tap {|e| e.prefix_test = true }
49
+ expectations << Expectation.new(line+offset, message, file.relative_path_from(dir)).tap {|e| e.prefix_test = true }
48
50
  end
49
51
 
50
52
  if src =~ /!expects(@(\+\d+))?/
@@ -52,11 +54,11 @@ ARGV.each do |arg|
52
54
  message = src.gsub!(/\A!expects(@\+\d+)? +/, '')
53
55
  line = comment.location.line
54
56
 
55
- expectations << Expectation.new(line+offset, message, file)
57
+ expectations << Expectation.new(line+offset, message, file.relative_path_from(dir))
56
58
  end
57
59
 
58
60
  if src =~ /ALLOW FAILURE/
59
- allowed_paths << file
61
+ allowed_paths << file.relative_path_from(dir)
60
62
  end
61
63
  end
62
64
 
@@ -67,18 +69,11 @@ ARGV.each do |arg|
67
69
  stderr = StringIO.new
68
70
  stdout = StringIO.new
69
71
 
70
- builtin = Pathname(__dir__) + "../stdlib"
71
72
  begin
72
- driver = Steep::Drivers::Check.new(source_paths: rb_files,
73
- signature_dirs: [builtin, dir],
74
- stdout: stdout,
75
- stderr: stderr)
76
-
77
- driver.fallback_any_is_error = false
78
- driver.allow_missing_definitions = false
79
-
80
73
  Rainbow.enabled = false
81
- driver.run
74
+ Dir.chdir(arg) do
75
+ Steep::Drivers::Check.new(stdout: stdout, stderr: stderr).run
76
+ end
82
77
  rescue => exn
83
78
  puts "ERROR: #{exn.inspect}"
84
79
  exn.backtrace.each do |loc|
@@ -100,7 +95,7 @@ ARGV.each do |arg|
100
95
  end
101
96
  end
102
97
 
103
- lines = stdout.string.each_line.to_a.map(&:chomp)
98
+ lines = stdout.string.each_line.to_a.map(&:chomp).reject {|line| line =~ /\bFallbackAny\b/ }
104
99
 
105
100
  expectations.each do |expectation|
106
101
  deleted = lines.reject! do |string|
data/exe/rbs ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.join(__dir__, "../vendor/ruby-signature/exe/ruby-signature")
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.join(__dir__, "../vendor/ruby-signature/exe/ruby-signature")
data/exe/steep CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'pathname'
4
4
 
5
+ $LOAD_PATH << Pathname(__dir__) + "../vendor/ruby-signature/lib"
5
6
  $LOAD_PATH << Pathname(__dir__) + "../lib"
6
7
 
7
8
  require 'steep'
data/lib/steep.rb CHANGED
@@ -11,6 +11,8 @@ require "listen"
11
11
  require 'pry'
12
12
  require 'language_server-protocol'
13
13
 
14
+ require "ruby/signature"
15
+
14
16
  require "steep/ast/namespace"
15
17
  require "steep/names"
16
18
  require "steep/ast/location"
@@ -32,29 +34,16 @@ require "steep/ast/types/boolean"
32
34
  require "steep/ast/types/tuple"
33
35
  require "steep/ast/types/proc"
34
36
  require "steep/ast/types/record"
35
- require "steep/ast/method_type"
36
37
  require "steep/ast/type_params"
37
- require "steep/ast/signature/class"
38
- require "steep/ast/signature/module"
39
- require "steep/ast/signature/members"
40
- require "steep/ast/signature/extension"
41
- require "steep/ast/signature/interface"
42
- require "steep/ast/signature/env"
43
- require "steep/ast/signature/const"
44
- require "steep/ast/signature/gvar"
45
- require "steep/ast/signature/alias"
46
38
  require "steep/ast/annotation"
47
39
  require "steep/ast/annotation/collection"
48
40
  require "steep/ast/buffer"
49
41
  require "steep/ast/builtin"
42
+ require "steep/ast/types/factory"
50
43
 
51
44
  require "steep/interface/method_type"
52
- require "steep/interface/method"
53
- require "steep/interface/builder"
54
45
  require "steep/interface/substitution"
55
- require "steep/interface/abstract"
56
- require "steep/interface/instantiated"
57
- require "steep/interface/ivar_chain"
46
+ require "steep/interface/interface"
58
47
 
59
48
  require "steep/subtyping/check"
60
49
  require "steep/subtyping/result"
@@ -65,8 +54,9 @@ require "steep/subtyping/variable_variance"
65
54
  require "steep/subtyping/variable_occurrence"
66
55
 
67
56
  require "steep/signature/errors"
68
- require "steep/parser"
57
+ require "steep/signature/validator"
69
58
  require "steep/source"
59
+ require "steep/annotation_parser"
70
60
  require "steep/typing"
71
61
  require "steep/errors"
72
62
  require "steep/type_construction"
@@ -74,19 +64,25 @@ require "steep/type_inference/send_args"
74
64
  require "steep/type_inference/block_params"
75
65
  require "steep/type_inference/constant_env"
76
66
  require "steep/type_inference/type_env"
67
+ require "steep/ast/types"
77
68
 
78
69
  require "steep/project"
79
70
  require "steep/project/file"
80
- require "steep/project/listener"
81
71
  require "steep/project/options"
82
- require "steep/drivers/utils/each_signature"
72
+ require "steep/project/target"
73
+ require "steep/project/dsl"
74
+ require "steep/project/file_loader"
75
+ require "steep/drivers/utils/driver_helper"
83
76
  require "steep/drivers/check"
84
77
  require "steep/drivers/validate"
85
78
  require "steep/drivers/annotations"
86
- require "steep/drivers/scaffold"
87
- require "steep/drivers/print_interface"
88
79
  require "steep/drivers/watch"
89
80
  require "steep/drivers/langserver"
81
+ require "steep/drivers/signature_error_printer"
82
+ require "steep/drivers/trace_printer"
83
+ require "steep/drivers/print_project"
84
+ require "steep/drivers/init"
85
+ require "steep/drivers/vendor"
90
86
 
91
87
  if ENV["NO_COLOR"]
92
88
  Rainbow.enabled = false
@@ -94,16 +90,26 @@ end
94
90
 
95
91
  module Steep
96
92
  def self.logger
97
- self.log_output = STDERR unless @logger
98
-
99
93
  @logger
100
94
  end
101
95
 
96
+ def self.new_logger(output, prev_level)
97
+ ActiveSupport::TaggedLogging.new(Logger.new(output)).tap do |logger|
98
+ logger.push_tags "Steep #{VERSION}"
99
+ logger.level = prev_level || Logger::WARN
100
+ end
101
+ end
102
+
103
+ def self.log_output
104
+ @log_output
105
+ end
106
+
102
107
  def self.log_output=(output)
108
+ @log_output = output
103
109
  prev_level = @logger&.level
104
-
105
- @logger = ActiveSupport::TaggedLogging.new(Logger.new(output))
106
- @logger.push_tags "Steep #{VERSION}"
107
- @logger.level = prev_level || Logger::WARN
110
+ @logger = new_logger(output, prev_level)
108
111
  end
112
+
113
+ @logger = nil
114
+ self.log_output = STDERR
109
115
  end