Sha256: 5eb08c428eab0da8d2e9f1588375ab426e665724a9d4bb93afdcc9616c035415

Contents?: true

Size: 721 Bytes

Versions: 7

Compression:

Stored size: 721 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

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-0.30.1 lib/rubocop/cop/style/array_join.rb
rubocop-0.30.0 lib/rubocop/cop/style/array_join.rb
rubocop-0.29.1 lib/rubocop/cop/style/array_join.rb
rubocop-0.29.0 lib/rubocop/cop/style/array_join.rb
rubocop-0.28.0 lib/rubocop/cop/style/array_join.rb
rubocop-0.27.1 lib/rubocop/cop/style/array_join.rb
rubocop-0.27.0 lib/rubocop/cop/style/array_join.rb