lib/rubocop/cop/internal_affairs/operator_keyword.rb in rubocop-1.69.1 vs lib/rubocop/cop/internal_affairs/operator_keyword.rb in rubocop-1.69.2
- old
+ new
@@ -15,10 +15,11 @@
#
class OperatorKeyword < Base
extend AutoCorrector
MSG = 'Use `%<prefer>s`.'
+ PREFERRED_METHOD = 'operator_keyword?'
# @!method and_or_type(node)
def_node_matcher :and_or_type, <<~PATTERN
{
(or $(send _node :and_type?) $(send _node :or_type?))
@@ -31,11 +32,12 @@
PATTERN
def on_or(node)
return unless (lhs, rhs = and_or_type(node))
- offense = lhs.receiver.source_range.join(rhs.source_range.end)
- prefer = "#{lhs.receiver.source}.operator_keyword?"
+ begin_range = lhs.receiver&.source_range || lhs.loc.selector
+ offense = begin_range.join(rhs.source_range.end)
+ prefer = lhs.receiver ? "#{lhs.receiver.source}.#{PREFERRED_METHOD}" : PREFERRED_METHOD
add_offense(offense, message: format(MSG, prefer: prefer)) do |corrector|
corrector.replace(offense, prefer)
end
end