Sha256: 33f8d237a5370237169878e84f8bd14315269b0008329643ba43774cc02ea61d

Contents?: true

Size: 636 Bytes

Versions: 4

Compression:

Stored size: 636 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class CollectionMethods < Cop
      MSG = 'Prefer %s over %s.'

      PREFERRED_METHODS = {
        collect: 'map',
        inject: 'reduce',
        detect: 'find',
        find_all: 'select'
      }

      def on_send(node)
        receiver, method_name, *_args = *node

        # a simple(but flawed way) to reduce false positives
        if receiver && PREFERRED_METHODS[method_name]
          add_offence(
            :convention,
            node.loc.line,
            sprintf(MSG, PREFERRED_METHODS[method_name], method_name)
          )
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.8.3 lib/rubocop/cop/collection_methods.rb
rubocop-0.8.2 lib/rubocop/cop/collection_methods.rb
rubocop-0.8.1 lib/rubocop/cop/collection_methods.rb
rubocop-0.8.0 lib/rubocop/cop/collection_methods.rb