Class: RuboCop::Cop::Rails::RedundantReceiverInWithOptions
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::RedundantReceiverInWithOptions
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb
Overview
Checks for redundant receiver in ‘with_options`. Receiver is implicit from Rails 4.2 or higher.
Constant Summary collapse
- MSG =
'Redundant receiver in `with_options`.'
Instance Method Summary collapse
- #on_block(node) ⇒ Object (also: #on_numblock)
Instance Method Details
#on_block(node) ⇒ Object Also known as: on_numblock
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb', line 71 def on_block(node) return unless node.method?(:with_options) return unless (body = node.body) return unless all_block_nodes_in(body).count.zero? send_nodes = all_send_nodes_in(body) return unless redundant_receiver?(send_nodes, node) send_nodes.each do |send_node| receiver = send_node.receiver add_offense(receiver) do |corrector| autocorrect(corrector, send_node, node) end end end |