Class: RuboCop::Cop::Sorbet::ForbidTCast

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RBSAssertionCorrection
Defined in:
lib/rubocop/cop/sorbet/forbid_t_cast.rb

Overview

Disallows using T.cast anywhere. Set AutocorrectToRBS: true to replace supported calls with RBS inline comments.

Examples:


# bad
T.cast(foo, Integer)

# good
foo #: as Integer

Constant Summary collapse

MSG =
"Do not use `T.cast`."
RESTRICT_ON_SEND =
[:cast].freeze

Constants included from RBSAssertionCorrection

RBSAssertionCorrection::COMMENT_START, RBSAssertionCorrection::NEWLINES

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object Also known as: on_csend



29
30
31
32
33
# File 'lib/rubocop/cop/sorbet/forbid_t_cast.rb', line 29

def on_send(node)
  return unless t_cast?(node)

  add_offense(node) { |corrector| autocorrect_t_cast_to_rbs(corrector, node) }
end

#t_cast?(node) ⇒ Object



27
# File 'lib/rubocop/cop/sorbet/forbid_t_cast.rb', line 27

def_node_matcher(:t_cast?, "(send (const nil? :T) :cast _ _)")