Open glortho opened 1 year ago
I think this would be challenging, because RuboCop has no knowledge of what the type of an object is. Given
object.serialize
or even something more explicit like
MyStruct.new(key: value).serialize
there would be no way for it to know if the receiver is a T::Struct
, T::Enum
, or some other object.
Maybe there is a way: https://github.com/Shopify/rubocop-sorbet/issues/142
As the Sorbet docs themselves admit,
T::Struct#serialize
has some surprising behavior, such that it is often better to implement serialization by hand.To avoid these issues, it would be nice to have a rule that disallows
T::Struct#serialize
. Ideally it would include these additional features:T::Enum#serialize
(which is safer)I'm happy to contribute an implementation for review, but I'd love to hear any feedback about this approach in the meantime!