Class: Rubocop::Cop::Style::Proc

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/style/proc.rb

Overview

This cops checks for uses of Proc.new where Kernel#proc would be more appropriate.

Constant Summary collapse

MSG =
'Use proc instead of Proc.new.'
TARGET =
s(:send, s(:const, nil, :Proc), :new)

Constants inherited from Cop

Cop::OPERATOR_METHODS

Instance Attribute Summary

Attributes inherited from Cop

#config, #corrections, #offences, #processed_source

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, all, #autocorrect?, #convention, #cop_config, cop_name, #cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, non_rails, rails?, style?, #support_autocorrect?, #warning

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#on_block(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/rubocop/cop/style/proc.rb', line 13

def on_block(node)
  # We're looking for
  # (block
  #   (send
  #     (const nil :Proc) :new)
  #   ...)
  block_method, = *node

  convention(block_method, :expression) if block_method == TARGET
end