Sha256: 8b7b206c3bb921cdc69a6ef1ac55181a664c89961941390bacb34ce588ae0251
Contents?: true
Size: 1.06 KB
Versions: 6
Compression:
Stored size: 1.06 KB
Contents
# encoding: utf-8 # frozen_string_literal: true module RuboCop module Cop module Performance # This cop is used to identify usages of # # @example # # bad # [].push(*a) # # # good # [].concat(a) class PushSplat < Cop include Parentheses MSG = 'Use `concat` instead of `push(*)`.'.freeze def_node_matcher :push_splat, <<-END (send _ :push (splat ...)) END def on_send(node) push_splat(node) do add_offense(node, :expression, MSG) end end def autocorrect(node) _receiver, _method, splat = *node body, = *splat lambda do |corrector| corrector.replace(node.location.selector, 'concat') source = if parens_required?(splat) "(#{body.source})" else body.source end corrector.replace(splat.loc.expression, source) end end end end end end
Version data entries
6 entries across 6 versions & 2 rubygems