Sha256: 663643cf38a0b512618a5b9674148f6a21680b55db3762278a8f37453cb9fa11

Contents?: true

Size: 756 Bytes

Versions: 2

Compression:

Stored size: 756 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

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.19.1 lib/rubocop/cop/style/proc.rb
rubocop-0.19.0 lib/rubocop/cop/style/proc.rb