Module: RuboCop::Cop::Sorbet::VoidSorbetAwareBehaviour

Defined in:
lib/rubocop/cop/sorbet/void_sorbet_aware_behaviour.rb

Overview

Patches Lint/Void to be aware of RBS inline #: absurd type assertions, which are used to mark unreachable branches in exhaustive case/when matching.

Without this patch, RuboCop 1.85+ flags the expression in the unreachable branch as "used in void context" because Lint/Void now inspects case/when branch bodies (rubocop/rubocop#14756).

Examples:


# good (not flagged)
#: ((String | Integer) x) -> void
def foo(x)
  case x
  when String
  when Integer
  else
    x #: absurd
  end
end

Constant Summary collapse

RBS_ABSURD_PATTERN =
/\A#:\s*absurd\s*\z/

Instance Method Summary collapse

Instance Method Details

#check_expression(expr) ⇒ Object



31
32
33
34
35
36
# File 'lib/rubocop/cop/sorbet/void_sorbet_aware_behaviour.rb', line 31

def check_expression(expr)
  return unless expr
  return if rbs_absurd_assertion?(expr)

  super
end