Sha256: bdc3f88ddc031e3f802377441fb4c52c429478585d4b3c5f63747e2cfa9396af

Contents?: true

Size: 714 Bytes

Versions: 9

Compression:

Stored size: 714 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)
          ->(corrector) { corrector.replace(node.loc.expression, 'proc') }
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/style/proc.rb
rubocop-0.35.0 lib/rubocop/cop/style/proc.rb
rubocop-0.34.2 lib/rubocop/cop/style/proc.rb
rubocop-0.34.1 lib/rubocop/cop/style/proc.rb
rubocop-0.34.0 lib/rubocop/cop/style/proc.rb
rubocop-0.33.0 lib/rubocop/cop/style/proc.rb
rubocop-0.32.1 lib/rubocop/cop/style/proc.rb
rubocop-0.32.0 lib/rubocop/cop/style/proc.rb
rubocop-0.31.0 lib/rubocop/cop/style/proc.rb