Sha256: aecd4130bbb563b9ef22134c8e52bf81b4ab12c9ff2b9becfeaf6f5fc58de1f1

Contents?: true

Size: 780 Bytes

Versions: 4

Compression:

Stored size: 780 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(:convention,
                        node.loc.selector,
                        MSG)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.12.0 lib/rubocop/cop/style/favor_join.rb
rubocop-0.11.1 lib/rubocop/cop/style/favor_join.rb
rubocop-0.11.0 lib/rubocop/cop/style/favor_join.rb
rubocop-0.10.0 lib/rubocop/cop/style/favor_join.rb