steep 0.11.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +27 -0
- data/.gitmodules +3 -0
- data/CHANGELOG.md +5 -0
- data/README.md +48 -90
- data/Rakefile +10 -6
- data/Steepfile +1 -0
- data/bin/setup +1 -0
- data/bin/smoke_runner.rb +9 -14
- data/exe/rbs +3 -0
- data/exe/ruby-signature +3 -0
- data/exe/steep +1 -0
- data/lib/steep.rb +32 -26
- data/lib/steep/annotation_parser.rb +167 -0
- data/lib/steep/ast/annotation/collection.rb +7 -7
- data/lib/steep/ast/types.rb +60 -0
- data/lib/steep/ast/types/any.rb +1 -1
- data/lib/steep/ast/types/factory.rb +535 -0
- data/lib/steep/ast/types/name.rb +3 -3
- data/lib/steep/ast/types/var.rb +1 -1
- data/lib/steep/cli.rb +56 -240
- data/lib/steep/drivers/annotations.rb +36 -19
- data/lib/steep/drivers/check.rb +55 -91
- data/lib/steep/drivers/init.rb +54 -0
- data/lib/steep/drivers/langserver.rb +241 -150
- data/lib/steep/drivers/print_project.rb +56 -0
- data/lib/steep/drivers/signature_error_printer.rb +25 -0
- data/lib/steep/drivers/trace_printer.rb +25 -0
- data/lib/steep/drivers/utils/driver_helper.rb +26 -0
- data/lib/steep/drivers/validate.rb +18 -38
- data/lib/steep/drivers/vendor.rb +46 -0
- data/lib/steep/drivers/watch.rb +78 -140
- data/lib/steep/errors.rb +22 -13
- data/lib/steep/interface/interface.rb +91 -0
- data/lib/steep/interface/method.rb +0 -4
- data/lib/steep/interface/method_type.rb +362 -2
- data/lib/steep/interface/substitution.rb +22 -0
- data/lib/steep/project.rb +25 -233
- data/lib/steep/project/dsl.rb +132 -0
- data/lib/steep/project/file.rb +93 -76
- data/lib/steep/project/file_loader.rb +63 -0
- data/lib/steep/project/options.rb +7 -0
- data/lib/steep/project/target.rb +190 -0
- data/lib/steep/signature/errors.rb +25 -77
- data/lib/steep/signature/validator.rb +122 -0
- data/lib/steep/source.rb +12 -7
- data/lib/steep/subtyping/check.rb +357 -633
- data/lib/steep/subtyping/constraints.rb +2 -2
- data/lib/steep/subtyping/trace.rb +23 -0
- data/lib/steep/type_construction.rb +509 -455
- data/lib/steep/type_inference/constant_env.rb +16 -24
- data/lib/steep/type_inference/type_env.rb +26 -18
- data/lib/steep/version.rb +1 -1
- data/sample/Steepfile +6 -0
- data/sample/lib/conference.rb +12 -0
- data/sample/sig/conference.rbs +6 -0
- data/smoke/alias/Steepfile +4 -0
- data/smoke/alias/a.rb +2 -2
- data/smoke/alias/{a.rbi → a.rbs} +1 -1
- data/smoke/and/Steepfile +4 -0
- data/smoke/array/Steepfile +4 -0
- data/smoke/array/a.rb +2 -2
- data/smoke/array/b.rb +4 -4
- data/smoke/array/c.rb +2 -2
- data/smoke/block/Steepfile +5 -0
- data/smoke/block/{a.rbi → a.rbs} +1 -1
- data/smoke/block/{c.rbi → c.rbs} +0 -0
- data/smoke/block/d.rb +6 -6
- data/smoke/case/Steepfile +4 -0
- data/smoke/case/a.rb +4 -3
- data/smoke/class/Steepfile +4 -0
- data/smoke/class/a.rb +1 -4
- data/smoke/class/a.rbs +24 -0
- data/smoke/class/h.rb +6 -2
- data/smoke/class/{h.rbi → h.rbs} +1 -2
- data/smoke/class/i.rb +1 -2
- data/smoke/class/i.rbs +9 -0
- data/smoke/const/Steepfile +4 -0
- data/smoke/dstr/Steepfile +4 -0
- data/smoke/ensure/Steepfile +4 -0
- data/smoke/ensure/a.rb +1 -1
- data/smoke/enumerator/Steepfile +4 -0
- data/smoke/enumerator/a.rb +7 -7
- data/smoke/enumerator/b.rb +6 -6
- data/smoke/extension/Steepfile +4 -0
- data/smoke/extension/{a.rbi → a.rbs} +2 -2
- data/smoke/extension/{e.rbi → e.rbs} +2 -2
- data/smoke/hash/Steepfile +4 -0
- data/smoke/hash/{a.rbi → a.rbs} +0 -0
- data/smoke/hash/b.rb +2 -2
- data/smoke/hash/c.rb +1 -1
- data/smoke/hash/e.rbs +3 -0
- data/smoke/hash/f.rb +1 -1
- data/smoke/hello/Steepfile +4 -0
- data/smoke/hello/hello.rbs +7 -0
- data/smoke/if/Steepfile +4 -0
- data/smoke/implements/Steepfile +4 -0
- data/smoke/implements/a.rbs +6 -0
- data/smoke/initialize/Steepfile +4 -0
- data/smoke/initialize/a.rbs +3 -0
- data/smoke/integer/Steepfile +4 -0
- data/smoke/integer/a.rb +5 -3
- data/smoke/interface/Steepfile +4 -0
- data/smoke/interface/{a.rbi → a.rbs} +0 -0
- data/smoke/kwbegin/Steepfile +4 -0
- data/smoke/lambda/Steepfile +4 -0
- data/smoke/lambda/a.rb +9 -2
- data/smoke/literal/Steepfile +4 -0
- data/smoke/literal/{literal_methods.rbi → literal_methods.rbs} +0 -0
- data/smoke/map/Steepfile +4 -0
- data/smoke/map/a.rb +1 -1
- data/smoke/method/Steepfile +4 -0
- data/smoke/method/{a.rbi → a.rbs} +0 -0
- data/smoke/method/b.rb +1 -4
- data/smoke/method/d.rb +1 -0
- data/smoke/method/d.rbs +3 -0
- data/smoke/module/Steepfile +4 -0
- data/smoke/module/a.rb +1 -1
- data/smoke/module/a.rbs +16 -0
- data/smoke/module/c.rb +1 -1
- data/smoke/regexp/Steepfile +4 -0
- data/smoke/regexp/a.rb +2 -2
- data/smoke/regexp/b.rb +16 -16
- data/smoke/regression/Steepfile +5 -0
- data/smoke/regression/array.rb +2 -2
- data/smoke/regression/hash.rb +2 -2
- data/smoke/regression/poly_new.rb +2 -0
- data/smoke/regression/poly_new.rbs +4 -0
- data/smoke/regression/set_divide.rb +2 -2
- data/smoke/rescue/Steepfile +4 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +4 -0
- data/smoke/self/a.rbs +4 -0
- data/smoke/skip/Steepfile +4 -0
- data/smoke/stdout/Steepfile +4 -0
- data/smoke/stdout/{a.rbi → a.rbs} +1 -1
- data/smoke/super/Steepfile +4 -0
- data/smoke/super/a.rbs +10 -0
- data/smoke/type_case/Steepfile +4 -0
- data/smoke/type_case/a.rb +1 -1
- data/smoke/yield/Steepfile +4 -0
- data/smoke/yield/a.rb +2 -2
- data/steep.gemspec +14 -7
- data/vendor/ruby-signature/.github/workflows/ruby.yml +27 -0
- data/vendor/ruby-signature/.gitignore +12 -0
- data/vendor/ruby-signature/.rubocop.yml +15 -0
- data/vendor/ruby-signature/BSDL +22 -0
- data/vendor/ruby-signature/COPYING +56 -0
- data/vendor/ruby-signature/Gemfile +6 -0
- data/vendor/ruby-signature/README.md +93 -0
- data/vendor/ruby-signature/Rakefile +66 -0
- data/vendor/ruby-signature/bin/annotate-with-rdoc +156 -0
- data/vendor/ruby-signature/bin/console +14 -0
- data/vendor/ruby-signature/bin/query-rdoc +103 -0
- data/vendor/ruby-signature/bin/setup +10 -0
- data/vendor/ruby-signature/bin/sort +88 -0
- data/vendor/ruby-signature/bin/test_runner.rb +17 -0
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +97 -0
- data/vendor/ruby-signature/docs/sigs.md +148 -0
- data/vendor/ruby-signature/docs/stdlib.md +152 -0
- data/vendor/ruby-signature/docs/syntax.md +528 -0
- data/vendor/ruby-signature/exe/rbs +3 -0
- data/vendor/ruby-signature/exe/ruby-signature +7 -0
- data/vendor/ruby-signature/lib/ruby/signature.rb +64 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +391 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +364 -0
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +52 -0
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +54 -0
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +534 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +152 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +172 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +921 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +283 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +138 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +126 -0
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +189 -0
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +104 -0
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +125 -0
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +93 -0
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +1343 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +441 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +579 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +383 -0
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +48 -0
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +63 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +290 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +58 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +324 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +185 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +256 -0
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +72 -0
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +932 -0
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +140 -0
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +49 -0
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +5 -0
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +271 -0
- data/vendor/ruby-signature/ruby-signature.gemspec +45 -0
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +3 -0
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +15 -0
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +1997 -0
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +280 -0
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +177 -0
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +35 -0
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +145 -0
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +116 -0
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +400 -0
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +37 -0
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +5 -0
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +2 -0
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +419 -0
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +606 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +404 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +260 -0
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +781 -0
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +582 -0
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +193 -0
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +68 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +12 -0
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +476 -0
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +59 -0
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +696 -0
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +121 -0
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +1029 -0
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +710 -0
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +683 -0
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +574 -0
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +135 -0
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +141 -0
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +66 -0
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +182 -0
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +248 -0
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +82 -0
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +409 -0
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +824 -0
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +426 -0
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +354 -0
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +93 -0
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +226 -0
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +424 -0
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +10 -0
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +131 -0
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +14 -0
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +55 -0
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +770 -0
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +13 -0
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +230 -0
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +1112 -0
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +23 -0
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +739 -0
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +91 -0
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +46 -0
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +159 -0
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +17 -0
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +18 -0
- data/vendor/ruby-signature/stdlib/find/find.rbs +44 -0
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +21 -0
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +23 -0
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +188 -0
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +9 -0
- data/vendor/ruby-signature/stdlib/set/set.rbs +77 -0
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +53 -0
- metadata +244 -54
- data/.travis.yml +0 -7
- data/lib/steep/ast/signature/alias.rb +0 -19
- data/lib/steep/ast/signature/class.rb +0 -33
- data/lib/steep/ast/signature/const.rb +0 -17
- data/lib/steep/ast/signature/env.rb +0 -138
- data/lib/steep/ast/signature/extension.rb +0 -21
- data/lib/steep/ast/signature/gvar.rb +0 -17
- data/lib/steep/ast/signature/interface.rb +0 -31
- data/lib/steep/ast/signature/members.rb +0 -115
- data/lib/steep/ast/signature/module.rb +0 -21
- data/lib/steep/drivers/print_interface.rb +0 -94
- data/lib/steep/drivers/scaffold.rb +0 -321
- data/lib/steep/drivers/utils/each_signature.rb +0 -31
- data/lib/steep/interface/abstract.rb +0 -68
- data/lib/steep/interface/builder.rb +0 -637
- data/lib/steep/interface/instantiated.rb +0 -163
- data/lib/steep/interface/ivar_chain.rb +0 -26
- data/lib/steep/parser.y +0 -1278
- data/lib/steep/project/listener.rb +0 -53
- data/smoke/class/a.rbi +0 -24
- data/smoke/class/d.rb +0 -9
- data/smoke/class/e.rb +0 -12
- data/smoke/class/i.rbi +0 -9
- data/smoke/hash/e.rbi +0 -3
- data/smoke/hello/hello.rbi +0 -7
- data/smoke/implements/a.rbi +0 -6
- data/smoke/initialize/a.rbi +0 -3
- data/smoke/module/a.rbi +0 -16
- data/smoke/self/a.rbi +0 -4
- data/smoke/super/a.rbi +0 -10
- data/stdlib/builtin.rbi +0 -787
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3a5b5a55253f50083410cd7d58bf7cda545301d9a7d5b72a5a8fd3865a76e93
|
4
|
+
data.tar.gz: fcf1273fc81c720266d4cdf2456d996b8f406137b204bb22fe1ad25852850a0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -8,32 +8,51 @@ Install via RubyGems.
|
|
8
8
|
|
9
9
|
### Requirements
|
10
10
|
|
11
|
-
Steep requires Ruby 2.
|
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 `.
|
39
|
+
Declare types in `.rbs` files in `sig` directory.
|
21
40
|
|
22
41
|
```
|
23
42
|
class Person
|
24
43
|
@name: String
|
25
|
-
@contacts: Array
|
44
|
+
@contacts: Array[Email | Phone]
|
26
45
|
|
27
|
-
def initialize: (name: String) ->
|
46
|
+
def initialize: (name: String) -> untyped
|
28
47
|
def name: -> String
|
29
|
-
def contacts: -> Array
|
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) ->
|
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) ->
|
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
|
67
|
+
def self.countries: -> Hash[String, String]
|
49
68
|
end
|
50
69
|
```
|
51
70
|
|
52
|
-
* You can use simple *generics*, like `Hash
|
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 `
|
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 `
|
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
|
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
|
-
##
|
162
|
+
## Prototyping signature
|
144
163
|
|
145
|
-
You can use `
|
164
|
+
You can use `rbs prototype` command to generate a signature declaration.
|
146
165
|
|
147
166
|
```
|
148
|
-
$
|
167
|
+
$ rbs prototype rb lib/person.rb lib/email.rb lib/phone.rb
|
149
168
|
class Person
|
150
|
-
@name:
|
151
|
-
@contacts: Array
|
152
|
-
def initialize: (name:
|
153
|
-
def guess_country: () ->
|
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:
|
158
|
-
def initialize: (address:
|
159
|
-
def ==: (
|
160
|
-
def hash: () ->
|
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:
|
165
|
-
@number:
|
166
|
-
def initialize: (country:
|
167
|
-
def ==: (
|
168
|
-
def hash: () ->
|
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
|
-
|
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 => :
|
12
|
-
task :test => :
|
13
|
-
task :install => :
|
11
|
+
task :build => :parser
|
12
|
+
task :test => :parser
|
13
|
+
task :install => [:reset, :parser]
|
14
14
|
|
15
|
-
|
16
|
-
|
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 :
|
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
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
|
-
|
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
data/exe/ruby-signature
ADDED
data/exe/steep
CHANGED
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/
|
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/
|
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/
|
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
|