lib/rubocop/cop/style/slicing_with_range.rb in rubocop-0.89.1 vs lib/rubocop/cop/style/slicing_with_range.rb in rubocop-0.90.0
- old
+ new
@@ -10,11 +10,12 @@
# # bad
# items[1..-1]
#
# # good
# items[1..]
- class SlicingWithRange < Cop
+ class SlicingWithRange < Base
+ extend AutoCorrector
extend TargetRubyVersion
minimum_target_ruby_version 2.6
MSG = 'Prefer ary[n..] over ary[n..-1].'
@@ -23,15 +24,11 @@
def on_send(node)
return unless node.method?(:[]) && node.arguments.count == 1
return unless range_till_minus_one?(node.arguments.first)
- add_offense(node.arguments.first)
- end
-
- def autocorrect(node)
- lambda do |corrector|
- corrector.remove(node.end)
+ add_offense(node.first_argument) do |corrector|
+ corrector.remove(node.first_argument.end)
end
end
end
end
end