Sha256: 52b4bd50be86a1464d158dab77798e1d755ea5a53346a6ed0ac31f9e146d8a15

Contents?: true

Size: 760 Bytes

Versions: 4

Compression:

Stored size: 760 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # This cops checks for uses of Proc.new where Kernel#proc
      # would be more appropriate.
      class Proc < Cop
        MSG = 'Use `proc` instead of `Proc.new`.'

        TARGET = s(:send, s(:const, nil, :Proc), :new)

        def on_block(node)
          # We're looking for
          # (block
          #   (send
          #     (const nil :Proc) :new)
          #   ...)
          block_method, = *node

          add_offense(block_method, :expression) if block_method == TARGET
        end

        def autocorrect(node)
          @corrections << lambda do |corrector|
            corrector.replace(node.loc.expression, 'proc')
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.22.0 lib/rubocop/cop/style/proc.rb
rubocop-0.21.0 lib/rubocop/cop/style/proc.rb
rubocop-0.20.1 lib/rubocop/cop/style/proc.rb
rubocop-0.20.0 lib/rubocop/cop/style/proc.rb