class RuboCop::Cop::Sorbet::BindingConstantWithoutTypeAlias
FooOrBar = T.type_alias(T.any(Foo, Bar))
# good
FooOrBar = T.any(Foo, Bar)
# bad
@example
to a constant directly. To bind the value, one must use ‘T.type_alias`.
This cop disallows binding the return value of `T.any`, `T.all`, `T.enum`
def autocorrect(node)
def autocorrect(node) lambda do |corrector| corrector.replace( node.source_range, "T.type_alias(#{node.source})" ) end end
def not_nil?(node)
def not_nil?(node) !node.nil? end
def not_t_let?(node)
def not_t_let?(node) !t_let?(node) end
def on_casgn(node)
def on_casgn(node) return unless binding_unaliased_type?(node) && !using_type_alias?(node.children[2]) add_offense( node.children[2], message: "It looks like you're trying to bind a type to a constant. " \ 'To do this, you must alias the type using `T.type_alias`.' ) end