Sha256: 87afb527b5129a8be9584fedb13f1590478fe8acbd4a9f3eaa0bd907d379dcf6

Contents?: true

Size: 789 Bytes

Versions: 6775

Compression:

Stored size: 789 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`.'.freeze

        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.source_range, 'proc') }
        end
      end
    end
  end
end

Version data entries

6,775 entries across 6,769 versions & 24 rubygems

Version Path
cybrid_api_bank_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_id_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_organization_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_bank_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_id_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_organization_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_bank_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_organization_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_id_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
ory-client-1.16.2 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_bank_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_organization_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_id_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_bank_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_id_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_organization_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
ory-client-1.16.1 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
ory-client-1.16.0 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb
cybrid_api_bank_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/proc.rb