Class: RuboCop::Cop::Rails::RedundantReceiverInWithOptions
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::Rails::RedundantReceiverInWithOptions
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb
Overview
This cop 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
Instance Method Details
#autocorrect(node) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb', line 95 def autocorrect(node) lambda do |corrector| corrector.remove(node.receiver.source_range) corrector.remove(node.loc.dot) corrector.remove(block_argument_range(node)) end end |
#on_block(node) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb', line 79 def on_block(node) (node) do |arg, body| return if body.nil? return unless all_block_nodes_in(body).count.zero? send_nodes = all_send_nodes_in(body) if send_nodes.all? { |n| same_value?(arg, n.receiver) } send_nodes.each do |send_node| receiver = send_node.receiver add_offense(send_node, location: receiver.source_range) end end end end |