Sha256: 5d04f68a27333fff54b4ed536c7be23e3ebf9eecb8c0beba2fd660aefc711af9

Contents?: true

Size: 769 Bytes

Versions: 10

Compression:

Stored size: 769 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for uses of Proc.new where Kernel#proc
      # would be more appropriate.
      #
      # @example
      #   # bad
      #   p = Proc.new { |n| puts n }
      #
      #   # good
      #   p = proc { |n| puts n }
      #
      class Proc < Cop
        MSG = 'Use `proc` instead of `Proc.new`.'

        def_node_matcher :proc_new?,
                         '(block $(send (const nil? :Proc) :new) ...)'

        def on_block(node)
          proc_new?(node) do |block_method|
            add_offense(block_method)
          end
        end

        def autocorrect(node)
          ->(corrector) { corrector.replace(node, 'proc') }
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
rubocop-0.86.0 lib/rubocop/cop/style/proc.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/style/proc.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/style/proc.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/style/proc.rb
rubocop-0.85.1 lib/rubocop/cop/style/proc.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/style/proc.rb
rubocop-0.85.0 lib/rubocop/cop/style/proc.rb
rubocop-0.84.0 lib/rubocop/cop/style/proc.rb
rubocop-0.83.0 lib/rubocop/cop/style/proc.rb
rubocop-0.82.0 lib/rubocop/cop/style/proc.rb