manual/cops_sorbet.md in rubocop-sorbet-0.7.3 vs manual/cops_sorbet.md in rubocop-sorbet-0.7.4
- old
+ new
@@ -39,10 +39,48 @@
# good
FooOrBar = T.type_alias { T.any(Foo, Bar) }
```
+## Sorbet/BuggyObsoleteStrictMemoization
+
+Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
+--- | --- | --- | --- | ---
+Enabled | Yes | Yes (Unsafe) | 0.7.3 | -
+
+Checks for the a mistaken variant of the "obsolete memoization pattern" that used to be required
+for older Sorbet versions in `#typed: strict` files. The mistaken variant would overwrite the ivar with `nil`
+on every call, causing the memoized value to be discarded and recomputed on every call.
+
+This cop will correct it to read from the ivar instead of `nil`, which will memoize it correctly.
+
+The result of this correction will be the "obsolete memoization pattern", which can further be corrected by
+the `Sorbet/ObsoleteStrictMemoization` cop.
+
+See `Sorbet/ObsoleteStrictMemoization` for more details.
+
+### Examples
+
+```ruby
+# bad
+sig { returns(Foo) }
+def foo
+ # This `nil` is likely a mistake, causing the memoized value to be discarded and recomputed on every call.
+ @foo = T.let(nil, T.nilable(Foo))
+ @foo ||= some_computation
+end
+
+# good
+sig { returns(Foo) }
+def foo
+ # This will now memoize the value as was likely intended, so `some_computation` is only ever called once.
+ # ⚠️If `some_computation` has side effects, this might be a breaking change!
+ @foo = T.let(@foo, T.nilable(Foo))
+ @foo ||= some_computation
+end
+```
+
## Sorbet/CallbackConditionalsBinding
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Disabled | No | Yes | 0.7.0 | -
@@ -380,9 +418,48 @@
### Configurable attributes
Name | Default value | Configurable values
--- | --- | ---
Exclude | `db/migrate/*.rb` | Array
+
+## Sorbet/ForbidTStruct
+
+Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
+--- | --- | --- | --- | ---
+Disabled | No | Yes | <<next>> | <<next>>
+
+Disallow using `T::Struct` and `T::Props`.
+
+### Examples
+
+```ruby
+# bad
+class MyStruct < T::Struct
+ const :foo, String
+ prop :bar, Integer, default: 0
+
+ def some_method; end
+end
+
+# good
+class MyStruct
+ extend T::Sig
+
+ sig { returns(String) }
+ attr_reader :foo
+
+ sig { returns(Integer) }
+ attr_accessor :bar
+
+ sig { params(foo: String, bar: Integer) }
+ def initialize(foo:, bar: 0)
+ @foo = foo
+ @bar = bar
+ end
+
+ def some_method; end
+end
+```
## Sorbet/ForbidTUnsafe
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---