Sha256: 9cfda31301f319b4361ae8a5dda6d4675e725dc613e0ca4e59933513172bd890
Contents?: true
Size: 921 Bytes
Versions: 30
Compression:
Stored size: 921 Bytes
Contents
# frozen_string_literal: true module RuboCop module Cop module Style # This cop checks that arrays are sliced with endless ranges instead of # `ary[start..-1]` on Ruby 2.6+. # # @example # # bad # items[1..-1] # # # good # items[1..] class SlicingWithRange < Base extend AutoCorrector extend TargetRubyVersion minimum_target_ruby_version 2.6 MSG = 'Prefer ary[n..] over ary[n..-1].' RESTRICT_ON_SEND = %i[[]].freeze def_node_matcher :range_till_minus_one?, '(irange !nil? (int -1))' def on_send(node) return unless node.arguments.count == 1 return unless range_till_minus_one?(node.arguments.first) add_offense(node.first_argument) do |corrector| corrector.remove(node.first_argument.end) end end end end end end
Version data entries
30 entries across 30 versions & 2 rubygems