Sha256: d950b0c40aebeb67cee1ec341d57a8aa71330b616f64b265b5186298cc579435

Contents?: true

Size: 777 Bytes

Versions: 6

Compression:

Stored size: 777 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? cbase} :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

6 entries across 6 versions & 2 rubygems

Version Path
rubocop-0.89.1 lib/rubocop/cop/style/proc.rb
rubocop-0.89.0 lib/rubocop/cop/style/proc.rb
rubocop-0.88.0 lib/rubocop/cop/style/proc.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/style/proc.rb
rubocop-0.87.1 lib/rubocop/cop/style/proc.rb
rubocop-0.87.0 lib/rubocop/cop/style/proc.rb