Sha256: 0f58609f91f21a863a4dccf90ec59aac7332d5eae828e727dcb212fb307b7242

Contents?: true

Size: 712 Bytes

Versions: 4

Compression:

Stored size: 712 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 FavorJoin < Cop
        MSG = 'Favor Array#join over Array#*.'

        def on_send(node)
          receiver_node, method_name, *arg_nodes = *node

          if receiver_node && receiver_node.type == :array &&
              method_name == :* && arg_nodes[0].type == :str
            add_offence(node, :selector)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.18.1 lib/rubocop/cop/style/favor_join.rb
rubocop-0.18.0 lib/rubocop/cop/style/favor_join.rb
rubocop-0.17.0 lib/rubocop/cop/style/favor_join.rb
rubocop-0.16.0 lib/rubocop/cop/style/favor_join.rb