sorbet-eraser 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/Gemfile.lock +1 -1
- data/README.md +28 -23
- data/lib/sorbet/eraser/parser.rb +4 -4
- data/lib/sorbet/eraser/patterns.rb +24 -0
- data/lib/sorbet/eraser/t.rb +75 -0
- data/lib/sorbet/eraser/version.rb +1 -1
- data/lib/t.rb +1 -73
- metadata +7 -6
- /data/lib/{t → sorbet/eraser/t}/enum.rb +0 -0
- /data/lib/{t → sorbet/eraser/t}/props.rb +0 -0
- /data/lib/{t → sorbet/eraser/t}/struct.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3859ee512cb01ed5b84df15af3dedaa629c30d122e80a7436821841f87184562
|
4
|
+
data.tar.gz: 8392610b8fb03ea78d2572b684c2ccf9b4806f082043e3b2614550a370eeea13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02ee32fc8bcf3d1951ddd9577a4f46c181a01f196eb6c2af34bb8bb0b68a0ebc3fb28515d0ca1e391d2d1ee305d3012aafd943918df643dd2a3a44c5272a38b2
|
7
|
+
data.tar.gz: fa7b5e80e3fda49d50df015532110f6b4050450c5348f4d9f0ac6f40c8e2b411882a5348b38e305419b74e0bf6e833b887997bb6757e440fb3acc552e286d7e4
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.4.0] - 2023-07-03
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- `require "t"` now requires a file that only requires `"sorbet/eraser/t"`, so they are effectively the same thing. If you're in a situation where you need to load a different `"t"`, then you can manually require `"sorbet/eraser/t"` and it should work.
|
14
|
+
- Replace all `typed:` comments with `typed: ignore`.
|
15
|
+
|
9
16
|
## [0.3.1] - 2023-06-27
|
10
17
|
|
11
18
|
### Added
|
@@ -34,7 +41,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
34
41
|
|
35
42
|
- Require MFA for releasing.
|
36
43
|
|
37
|
-
[unreleased]: https://github.com/kddnewton/sorbet-eraser/compare/v0.
|
44
|
+
[unreleased]: https://github.com/kddnewton/sorbet-eraser/compare/v0.4.0...HEAD
|
45
|
+
[0.4.0]: https://github.com/kddnewton/sorbet-eraser/compare/v0.3.1...v0.4.0
|
46
|
+
[0.3.1]: https://github.com/kddnewton/sorbet-eraser/compare/v0.3.0...v0.3.1
|
38
47
|
[0.3.0]: https://github.com/kddnewton/sorbet-eraser/compare/v0.2.0...v0.3.0
|
39
48
|
[0.2.0]: https://github.com/kddnewton/sorbet-eraser/compare/v0.1.1...v0.2.0
|
40
49
|
[0.1.1]: https://github.com/kddnewton/sorbet-eraser/compare/f6a712...v0.1.1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -12,6 +12,8 @@ Sometimes, you want to use Sorbet for development, but don't want to run `sorbet
|
|
12
12
|
To handle these use cases, `sorbet-eraser` provides a way to erase all traces of `sorbet-runtime` code from your source code. This means that you can use Sorbet for development, but not have to worry about `sorbet-runtime` in production. For example,
|
13
13
|
|
14
14
|
```ruby
|
15
|
+
# typed: true
|
16
|
+
|
15
17
|
class HelloWorld
|
16
18
|
extend T::Sig
|
17
19
|
|
@@ -25,6 +27,8 @@ end
|
|
25
27
|
will be transformed into
|
26
28
|
|
27
29
|
```ruby
|
30
|
+
|
31
|
+
|
28
32
|
class HelloWorld
|
29
33
|
|
30
34
|
|
@@ -91,29 +95,30 @@ If you used any runtime structures like `T::Struct` or `T::Enum` you'll need a r
|
|
91
95
|
|
92
96
|
Below is a table of the status of each `sorbet-runtime` construct and its current support status.
|
93
97
|
|
94
|
-
| Construct | Status | Replacement
|
95
|
-
| --------------------------------------------------- | ------ |
|
96
|
-
| `
|
97
|
-
| `
|
98
|
-
| `
|
99
|
-
| `
|
100
|
-
| `
|
101
|
-
| `class Foo < T::
|
102
|
-
| `class Foo < T::
|
103
|
-
| `class Foo < T::
|
104
|
-
| `
|
105
|
-
| `include T::Props
|
106
|
-
| `include T::Props::
|
107
|
-
| `
|
108
|
-
| `
|
109
|
-
| `T.
|
110
|
-
| `T.
|
111
|
-
| `T.
|
112
|
-
| `T.
|
113
|
-
| `T.
|
114
|
-
| `T.
|
115
|
-
| `T.
|
116
|
-
| `T.
|
98
|
+
| Construct | Status | Replacement |
|
99
|
+
| --------------------------------------------------- | ------ | ----------------- |
|
100
|
+
| `# typed: foo` | ✅ | `# typed: ignore` |
|
101
|
+
| `extend T::*` | ✅ | Shimmed |
|
102
|
+
| `abstract!`, `final!`, `interface!`, `sealed!` | ✅ | Shimmed |
|
103
|
+
| `mixes_in_class_methods(*)`, `requires_ancestor(*)` | ✅ | Shimmed |
|
104
|
+
| `type_member(*)`, `type_template(*)` | ✅ | Shimmed |
|
105
|
+
| `class Foo < T::Enum` | ✅ | Shimmed |
|
106
|
+
| `class Foo < T::InexactStruct` | 🛠 | Shimmed |
|
107
|
+
| `class Foo < T::Struct` | 🛠 | Shimmed |
|
108
|
+
| `class Foo < T::ImmutableStruct` | 🛠 | Shimmed |
|
109
|
+
| `include T::Props` | 🛠 | Shimmed |
|
110
|
+
| `include T::Props::Serializable` | 🛠 | Shimmed |
|
111
|
+
| `include T::Props::Constructor` | 🛠 | Shimmed |
|
112
|
+
| `sig` | ✅ | Removed |
|
113
|
+
| `T.absurd(foo)` | ✅ | Shimmed |
|
114
|
+
| `T.assert_type!(foo, bar)` | ✅ | `foo` |
|
115
|
+
| `T.bind(self, foo)` | ✅ | `self` |
|
116
|
+
| `T.cast(foo, bar)` | ✅ | `foo` |
|
117
|
+
| `T.let(foo, bar)` | ✅ | `foo` |
|
118
|
+
| `T.must(foo)` | ✅ | `foo` |
|
119
|
+
| `T.reveal_type(foo)` | ✅ | `foo` |
|
120
|
+
| `T.type_alias { foo }` | ✅ | Shimmed |
|
121
|
+
| `T.unsafe(foo)` | ✅ | `foo` |
|
117
122
|
|
118
123
|
In the above table, for `Status`:
|
119
124
|
|
data/lib/sorbet/eraser/parser.rb
CHANGED
@@ -86,7 +86,7 @@ module Sorbet
|
|
86
86
|
@line_counts << MultiByteString.new(last_index, line)
|
87
87
|
end
|
88
88
|
|
89
|
-
last_index += line.
|
89
|
+
last_index += line.bytesize
|
90
90
|
end
|
91
91
|
|
92
92
|
@errors = []
|
@@ -213,7 +213,7 @@ module Sorbet
|
|
213
213
|
# Track the open heredocs so we can replace the string literal ranges with
|
214
214
|
# the range of their declarations.
|
215
215
|
def on_heredoc_beg(value)
|
216
|
-
range = loc.then { |start| start...(start + value.
|
216
|
+
range = loc.then { |start| start...(start + value.bytesize) }
|
217
217
|
heredocs << [range, value, nil]
|
218
218
|
|
219
219
|
Node.new(:@heredoc_beg, [value], range)
|
@@ -222,7 +222,7 @@ module Sorbet
|
|
222
222
|
# If a heredoc ends, then the next string literal event will be the
|
223
223
|
# heredoc.
|
224
224
|
def on_heredoc_end(value)
|
225
|
-
range = loc.then { |start| start...(start + value.
|
225
|
+
range = loc.then { |start| start...(start + value.bytesize) }
|
226
226
|
heredocs.find { |(_, beg_arg, end_arg)| beg_arg.include?(value.strip) && end_arg.nil? }[2] = value
|
227
227
|
|
228
228
|
Node.new(:@heredoc_end, [value], range)
|
@@ -251,7 +251,7 @@ module Sorbet
|
|
251
251
|
next if handled.include?(:"on_#{event}")
|
252
252
|
|
253
253
|
define_method(:"on_#{event}") do |value|
|
254
|
-
range = loc.then { |start| start...(start + (value&.
|
254
|
+
range = loc.then { |start| start...(start + (value&.bytesize || 0)) }
|
255
255
|
Node.new(:"@#{event}", [value], range)
|
256
256
|
end
|
257
257
|
end
|
@@ -100,6 +100,30 @@ module Sorbet
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
+
# typed: ignore
|
104
|
+
# typed: false
|
105
|
+
# typed: true
|
106
|
+
# typed: strong
|
107
|
+
class TypedCommentPattern < Pattern
|
108
|
+
def replace(segment)
|
109
|
+
segment.gsub(/(\A#\s*typed:\s*)(?:ignore|false|true|strong)(\s*)\z/) do
|
110
|
+
"#{$1}ignore#{$2}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def on_comment(comment)
|
116
|
+
super.tap do |node|
|
117
|
+
if lineno == 1 && comment.match?(/\A#\s*typed:\s*(?:ignore|false|true|strong)\s*\z/)
|
118
|
+
# typed: ignore
|
119
|
+
# typed: false
|
120
|
+
# typed: true
|
121
|
+
# typed: strong
|
122
|
+
patterns << TypedCommentPattern.new(node.range)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
103
127
|
def on_method_add_arg(call, arg_paren)
|
104
128
|
if call.match?(/\A<call <var_ref <@const T>> <@period \.> <@ident (?:must|reveal_type|unsafe)>>\z/) && arg_paren.match?(/\A<arg_paren <args_add_block <args .+> false>>\z/)
|
105
129
|
# T.must(foo)
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sorbet/eraser/t/enum"
|
4
|
+
require "sorbet/eraser/t/props"
|
5
|
+
require "sorbet/eraser/t/struct"
|
6
|
+
|
7
|
+
# For some constructs, it doesn't make as much sense to entirely remove them
|
8
|
+
# since they're actually used to change runtime behavior. For example, T.absurd
|
9
|
+
# will always raise an error. In this case instead of removing the content, we
|
10
|
+
# can just shim it.
|
11
|
+
module T
|
12
|
+
# These methods should really not be being called in a loop or any other kind
|
13
|
+
# of hot path, so here we're just going to shim them.
|
14
|
+
module Helpers
|
15
|
+
def abstract!; end
|
16
|
+
def interface!; end
|
17
|
+
def final!; end
|
18
|
+
def sealed!; end
|
19
|
+
def mixes_in_class_methods(*); end
|
20
|
+
def requires_ancestor(*); end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Similar to the Helpers module, these things should only be called a couple
|
24
|
+
# of times, so shimming them here.
|
25
|
+
module Generic
|
26
|
+
include Helpers
|
27
|
+
def type_member(*, **); end
|
28
|
+
def type_template(*, **); end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Keeping this module as a thing so that if there's any kind of weird
|
32
|
+
# reflection going on like is_a?(T::Sig) it will still work.
|
33
|
+
module Sig
|
34
|
+
end
|
35
|
+
|
36
|
+
# I really don't want to be shimming this, but there are places where people
|
37
|
+
# try to reference these values.
|
38
|
+
module Private
|
39
|
+
module RuntimeLevels
|
40
|
+
def self.default_checked_level; :never; end
|
41
|
+
end
|
42
|
+
|
43
|
+
module Methods
|
44
|
+
module MethodHooks
|
45
|
+
end
|
46
|
+
|
47
|
+
module SingletonMethodHooks
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.signature_for_method(method); method; end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# I also don't want to shim this, but there are places where people will
|
55
|
+
# reference it.
|
56
|
+
module Configuration
|
57
|
+
class << self
|
58
|
+
attr_accessor :inline_type_error_handler,
|
59
|
+
:call_validation_error_handler,
|
60
|
+
:sig_builder_error_handler
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Type aliases don't actually do anything, but they are usually assigned to
|
65
|
+
# constants, so in that case we need to return something.
|
66
|
+
def self.type_alias
|
67
|
+
Object.new
|
68
|
+
end
|
69
|
+
|
70
|
+
# Absurd always raises a TypeError within Sorbet, so mirroring that behavior
|
71
|
+
# here when T.absurd is called.
|
72
|
+
def self.absurd(value)
|
73
|
+
raise TypeError, value
|
74
|
+
end
|
75
|
+
end
|
data/lib/t.rb
CHANGED
@@ -1,75 +1,3 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "t
|
4
|
-
require "t/props"
|
5
|
-
require "t/struct"
|
6
|
-
|
7
|
-
# For some constructs, it doesn't make as much sense to entirely remove them
|
8
|
-
# since they're actually used to change runtime behavior. For example, T.absurd
|
9
|
-
# will always raise an error. In this case instead of removing the content, we
|
10
|
-
# can just shim it.
|
11
|
-
module T
|
12
|
-
# These methods should really not be being called in a loop or any other kind
|
13
|
-
# of hot path, so here we're just going to shim them.
|
14
|
-
module Helpers
|
15
|
-
def abstract!; end
|
16
|
-
def interface!; end
|
17
|
-
def final!; end
|
18
|
-
def sealed!; end
|
19
|
-
def mixes_in_class_methods(*); end
|
20
|
-
def requires_ancestor(*); end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Similar to the Helpers module, these things should only be called a couple
|
24
|
-
# of times, so shimming them here.
|
25
|
-
module Generic
|
26
|
-
include Helpers
|
27
|
-
def type_member(*, **); end
|
28
|
-
def type_template(*, **); end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Keeping this module as a thing so that if there's any kind of weird
|
32
|
-
# reflection going on like is_a?(T::Sig) it will still work.
|
33
|
-
module Sig
|
34
|
-
end
|
35
|
-
|
36
|
-
# I really don't want to be shimming this, but there are places where people
|
37
|
-
# try to reference these values.
|
38
|
-
module Private
|
39
|
-
module RuntimeLevels
|
40
|
-
def self.default_checked_level; :never; end
|
41
|
-
end
|
42
|
-
|
43
|
-
module Methods
|
44
|
-
module MethodHooks
|
45
|
-
end
|
46
|
-
|
47
|
-
module SingletonMethodHooks
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.signature_for_method(method); method; end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# I also don't want to shim this, but there are places where people will
|
55
|
-
# reference it.
|
56
|
-
module Configuration
|
57
|
-
class << self
|
58
|
-
attr_accessor :inline_type_error_handler,
|
59
|
-
:call_validation_error_handler,
|
60
|
-
:sig_builder_error_handler
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# Type aliases don't actually do anything, but they are usually assigned to
|
65
|
-
# constants, so in that case we need to return something.
|
66
|
-
def self.type_alias
|
67
|
-
Object.new
|
68
|
-
end
|
69
|
-
|
70
|
-
# Absurd always raises a TypeError within Sorbet, so mirroring that behavior
|
71
|
-
# here when T.absurd is called.
|
72
|
-
def self.absurd(value)
|
73
|
-
raise TypeError, value
|
74
|
-
end
|
75
|
-
end
|
3
|
+
require "sorbet/eraser/t"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorbet-eraser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Newton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,18 +77,19 @@ files:
|
|
77
77
|
- lib/sorbet/eraser/cli.rb
|
78
78
|
- lib/sorbet/eraser/parser.rb
|
79
79
|
- lib/sorbet/eraser/patterns.rb
|
80
|
+
- lib/sorbet/eraser/t.rb
|
81
|
+
- lib/sorbet/eraser/t/enum.rb
|
82
|
+
- lib/sorbet/eraser/t/props.rb
|
83
|
+
- lib/sorbet/eraser/t/struct.rb
|
80
84
|
- lib/sorbet/eraser/version.rb
|
81
85
|
- lib/t.rb
|
82
|
-
- lib/t/enum.rb
|
83
|
-
- lib/t/props.rb
|
84
|
-
- lib/t/struct.rb
|
85
86
|
- sorbet-eraser.gemspec
|
86
87
|
homepage: https://github.com/kddnewton/sorbet-eraser
|
87
88
|
licenses:
|
88
89
|
- MIT
|
89
90
|
metadata:
|
90
91
|
bug_tracker_uri: https://github.com/kddnewton/sorbet-eraser/issues
|
91
|
-
changelog_uri: https://github.com/kddnewton/sorbet-eraser/blob/v0.
|
92
|
+
changelog_uri: https://github.com/kddnewton/sorbet-eraser/blob/v0.4.0/CHANGELOG.md
|
92
93
|
source_code_uri: https://github.com/kddnewton/sorbet-eraser
|
93
94
|
rubygems_mfa_required: 'true'
|
94
95
|
post_install_message:
|
File without changes
|
File without changes
|
File without changes
|