Class: RuboCop::Cop::TypeToolkit::PreferNotNil

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/type_toolkit/prefer_not_nil.rb

Overview

Replaces Sorbet's T.must(value) assertion with Type Toolkit's value.not_nil! assertion.

Constant Summary collapse

MSG =
"Use `.not_nil!` instead of `T.must()`."
RESTRICT_ON_SEND =
[:must].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object

Signature:

  • (RuboCop::AST::SendNode) -> void



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rubocop/cop/type_toolkit/prefer_not_nil.rb', line 21

def on_send(node)
  return unless (argument = extract_t_must_argument(node))

  if nested_t_must?(node)
    add_offense(node, message: MSG)
  else
    replacement = replacement_for(argument)
    correction = correction_for(node, argument, replacement)

    add_offense(node, message: MSG) do |corrector|
      corrector.replace(node, correction)
    end
  end
end