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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbfc0c7e028bd4e712e64d29a7c74e65d45937087a3f510f01afab434250b3d5
4
- data.tar.gz: 6a89286f19c7ae6ed8e838beba49fcb799426fb14a58ed4b5c3b32d9b59935dc
3
+ metadata.gz: 3859ee512cb01ed5b84df15af3dedaa629c30d122e80a7436821841f87184562
4
+ data.tar.gz: 8392610b8fb03ea78d2572b684c2ccf9b4806f082043e3b2614550a370eeea13
5
5
  SHA512:
6
- metadata.gz: efe378c67fa4749ac7461496d895c69e89ef28ca1f71d6c9385952a96320e8849a6ed15604d8219560903d047b0f9a1eda60fb938b07dc633f55da95a1082119
7
- data.tar.gz: af3a02739fbbfdec2fd98c1bbb749b74a2a7f088c237f339966b186ad4b565e8cd353bac2bd4989f2fba8ae7435a096a058c4aca5cded0f209113826e284e994
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.3.0...HEAD
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sorbet-eraser (0.3.1)
4
+ sorbet-eraser (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- | `extend T::*` | ✅ | Shimmed |
97
- | `abstract!`, `final!`, `interface!`, `sealed!` | ✅ | Shimmed |
98
- | `mixes_in_class_methods(*)`, `requires_ancestor(*)` | ✅ | Shimmed |
99
- | `type_member(*)`, `type_template(*)` | ✅ | Shimmed |
100
- | `class Foo < T::Enum` | ✅ | Shimmed |
101
- | `class Foo < T::InexactStruct` | 🛠 | Shimmed |
102
- | `class Foo < T::Struct` | 🛠 | Shimmed |
103
- | `class Foo < T::ImmutableStruct` | 🛠 | Shimmed |
104
- | `include T::Props` | 🛠 | Shimmed |
105
- | `include T::Props::Serializable` | 🛠 | Shimmed |
106
- | `include T::Props::Constructor` | 🛠 | Shimmed |
107
- | `sig` | | Removed |
108
- | `T.absurd(foo)` | ✅ | Shimmed |
109
- | `T.assert_type!(foo, bar)` | ✅ | `foo` |
110
- | `T.bind(self, foo)` | ✅ | `self` |
111
- | `T.cast(foo, bar)` | ✅ | `foo` |
112
- | `T.let(foo, bar)` | ✅ | `foo` |
113
- | `T.must(foo)` | ✅ | `foo` |
114
- | `T.reveal_type(foo)` | ✅ | `foo` |
115
- | `T.type_alias { foo }` | ✅ | Shimmed |
116
- | `T.unsafe(foo)` | ✅ | `foo` |
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
 
@@ -86,7 +86,7 @@ module Sorbet
86
86
  @line_counts << MultiByteString.new(last_index, line)
87
87
  end
88
88
 
89
- last_index += line.size
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.size) }
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.size) }
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&.size || 0)) }
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sorbet
4
4
  module Eraser
5
- VERSION = "0.3.1"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
data/lib/t.rb CHANGED
@@ -1,75 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "t/enum"
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.3.1
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-06-27 00:00:00.000000000 Z
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.3.1/CHANGELOG.md
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