Sha256: 28d56f92346379168b84279b2318eb3f0333632f4cecf7d3f1835ea0fc08a51a

Contents?: true

Size: 709 Bytes

Versions: 8

Compression:

Stored size: 709 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for uses of "*" as a substitute for *join*.
      #
      # Not all cases can reliably checked, due to Ruby's dynamic
      # types, so we consider only cases when the first argument is an
      # array literal or the second is a string literal.
      class ArrayJoin < Cop
        MSG = 'Favor `Array#join` over `Array#*`.'

        def on_send(node)
          receiver_node, method_name, *arg_nodes = *node
          return unless receiver_node && receiver_node.type == :array &&
            method_name == :* && arg_nodes[0].type == :str

          add_offense(node, :selector)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/array_join.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/array_join.rb
rubocop-0.26.1 lib/rubocop/cop/style/array_join.rb
rubocop-0.26.0 lib/rubocop/cop/style/array_join.rb
rubocop-0.25.0 lib/rubocop/cop/style/array_join.rb
rubocop-0.24.1 lib/rubocop/cop/style/array_join.rb
rubocop-0.24.0 lib/rubocop/cop/style/array_join.rb
rubocop-0.23.0 lib/rubocop/cop/style/array_join.rb