lib/rubocop/cop/mixin/nil_assertion_handleable.rb in rubocop-minitest-0.17.2 vs lib/rubocop/cop/mixin/nil_assertion_handleable.rb in rubocop-minitest-0.18.0
- old
+ new
@@ -3,11 +3,11 @@
module RuboCop
module Cop
module Minitest
# Common functionality for `AssertNil` and `RefuteNil` cops.
module NilAssertionHandleable
- MSG = 'Prefer using `%<assertion_type>s_nil(%<preferred_args>s)` over `%<method>s(%<current_args>s)`.'
+ MSG = 'Prefer using `%<assertion_type>s_nil(%<preferred_args>s)`.'
private
def register_offense(node, actual, message)
message = build_message(node, actual, message)
@@ -20,35 +20,30 @@
def build_message(node, actual, message)
message = message.first
message_source = message&.source
preferred_args = [actual.source, message_source].compact
- current_args = if comparison_assertion_method?(node)
- ['nil', preferred_args].join(', ')
- else
- ["#{actual.source}.nil?", message_source].compact.join(', ')
- end
format(
MSG,
assertion_type: assertion_type,
preferred_args: preferred_args.join(', '),
- method: node.method_name, current_args: current_args
+ method: node.method_name
)
end
def autocorrect(corrector, node, actual)
corrector.replace(node.loc.selector, :"#{assertion_type}_nil")
- if comparison_assertion_method?(node)
+ if comparison_or_predicate_assertion_method?(node)
corrector.replace(first_and_second_arguments_range(node), actual.source)
else
corrector.remove(node.first_argument.loc.dot)
corrector.remove(node.first_argument.loc.selector)
end
end
- def comparison_assertion_method?(node)
- node.method?(:"#{assertion_type}_equal")
+ def comparison_or_predicate_assertion_method?(node)
+ node.method?(:"#{assertion_type}_equal") || node.method?(:"#{assertion_type}_predicate")
end
end
end
end
end