Sha256: 40166b2a41f659501f10fb279b0c1836211eb1cff2ebf62e97304530787426d9

Contents?: true

Size: 690 Bytes

Versions: 13

Compression:

Stored size: 690 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class CollectionMethods < Cop
      PREFERRED_METHODS = {
        'collect' => 'map',
        'inject' => 'reduce',
        'detect' => 'find',
        'find_all' => 'select',
      }

      def inspect(file, source, tokens, sexp)
        each(:call, sexp) do |s|
          s.drop(2).each_slice(2) do |m|
            method_name = m[1][1]
            if PREFERRED_METHODS[method_name]
              add_offence(
                :convention,
                m[1][2].lineno,
                "Prefer #{PREFERRED_METHODS[method_name]} over #{method_name}."
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rubocop-0.7.2 lib/rubocop/cop/collection_methods.rb
rubocop-0.7.1 lib/rubocop/cop/collection_methods.rb
rubocop-0.7.0 lib/rubocop/cop/collection_methods.rb
rubocop-0.6.1 lib/rubocop/cop/collection_methods.rb
rubocop-0.6.0 lib/rubocop/cop/collection_methods.rb
rubocop-0.5.0 lib/rubocop/cop/collection_methods.rb
rubocop-0.4.6 lib/rubocop/cop/collection_methods.rb
rubocop-0.4.5 lib/rubocop/cop/collection_methods.rb
rubocop-0.4.4 lib/rubocop/cop/collection_methods.rb
rubocop-0.4.3 lib/rubocop/cop/collection_methods.rb
rubocop-0.4.2 lib/rubocop/cop/collection_methods.rb
rubocop-0.4.1 lib/rubocop/cop/collection_methods.rb
rubocop-0.4.0 lib/rubocop/cop/collection_methods.rb