lib/rubocop/cop/minitest/assert_empty_literal.rb in rubocop-minitest-0.11.1 vs lib/rubocop/cop/minitest/assert_empty_literal.rb in rubocop-minitest-0.12.0
- old
+ new
@@ -12,12 +12,13 @@
# assert_equal({}, object)
#
# # good
# assert_empty(object)
#
- class AssertEmptyLiteral < Cop
+ class AssertEmptyLiteral < Base
include ArgumentRangeHelper
+ extend AutoCorrector
MSG = 'Prefer using `assert_empty(%<arguments>s)` over ' \
'`assert_equal(%<literal>s, %<arguments>s)`.'
RESTRICT_ON_SEND = %i[assert_equal].freeze
@@ -30,18 +31,12 @@
return unless literal.values.empty?
args = matchers.map(&:source).join(', ')
message = format(MSG, literal: literal.source, arguments: args)
- add_offense(node, message: message)
- end
- end
+ add_offense(node, message: message) do |corrector|
+ object = matchers.first
- def autocorrect(node)
- assert_equal_with_empty_literal(node) do |_literal, matchers|
- object = matchers.first
-
- lambda do |corrector|
corrector.replace(node.loc.selector, 'assert_empty')
corrector.replace(first_and_second_arguments_range(node), object.source)
end
end
end