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