Sha256: 56b39f414913c50de2275bb53484fad7c741800c227cec26b7cdd3f630d5bfd2

Contents?: true

Size: 760 Bytes

Versions: 15

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

15 entries across 15 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/proc.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/proc.rb
rubocop-0.30.1 lib/rubocop/cop/style/proc.rb
rubocop-0.30.0 lib/rubocop/cop/style/proc.rb
rubocop-0.29.1 lib/rubocop/cop/style/proc.rb
rubocop-0.29.0 lib/rubocop/cop/style/proc.rb
rubocop-0.28.0 lib/rubocop/cop/style/proc.rb
rubocop-0.27.1 lib/rubocop/cop/style/proc.rb
rubocop-0.27.0 lib/rubocop/cop/style/proc.rb
rubocop-0.26.1 lib/rubocop/cop/style/proc.rb
rubocop-0.26.0 lib/rubocop/cop/style/proc.rb
rubocop-0.25.0 lib/rubocop/cop/style/proc.rb
rubocop-0.24.1 lib/rubocop/cop/style/proc.rb
rubocop-0.24.0 lib/rubocop/cop/style/proc.rb
rubocop-0.23.0 lib/rubocop/cop/style/proc.rb