lib/rubocop/cop/minitest/refute_nil.rb in rubocop-minitest-0.11.1 vs lib/rubocop/cop/minitest/refute_nil.rb in rubocop-minitest-0.12.0
- old
+ new
@@ -13,12 +13,13 @@
#
# # good
# refute_nil(actual)
# refute_nil(actual, 'message')
#
- class RefuteNil < Cop
+ class RefuteNil < Base
include ArgumentRangeHelper
+ extend AutoCorrector
MSG = 'Prefer using `refute_nil(%<arguments>s)` over ' \
'`refute_equal(nil, %<arguments>s)`.'
RESTRICT_ON_SEND = %i[refute_equal].freeze
@@ -30,16 +31,10 @@
refute_equal_with_nil(node) do |actual, message|
message = message.first
arguments = [actual.source, message&.source].compact.join(', ')
- add_offense(node, message: format(MSG, arguments: arguments))
- end
- end
-
- def autocorrect(node)
- lambda do |corrector|
- refute_equal_with_nil(node) do |actual|
+ add_offense(node, message: format(MSG, arguments: arguments)) do |corrector|
corrector.replace(node.loc.selector, 'refute_nil')
corrector.replace(
first_and_second_arguments_range(node), actual.source
)
end