Skip to content

Commit 3bf55b3

Browse files
committed
[Fix rubocop#794] Fix an error for Rails/RedundantReceiverInWithOptions
Fixes rubocop#794. This PR fixes an error for `Rails/RedundantReceiverInWithOptions` when calling a method with a receiver in `with_options` without block arguments
1 parent a94f456 commit 3bf55b3

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#794](https://github.com/rubocop/rubocop-rails/issues/794): Fix an error for `Rails/RedundantReceiverInWithOptions` when calling a method with a receiver in `with_options` without block arguments. ([@koic][])

lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ def redundant_receiver?(send_nodes, node)
9898
proc = if node.numblock_type?
9999
->(n) { n.receiver.lvar_type? && n.receiver.source == '_1' }
100100
else
101+
return false if node.arguments.empty?
102+
101103
arg = node.arguments.first
102104
->(n) { same_value?(arg, n.receiver) }
103105
end

spec/rubocop/cop/rails/redundant_receiver_in_with_options_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ class Account < ApplicationRecord
108108
RUBY
109109
end
110110

111+
it 'does not register an offense when calling a method with a receiver in `with_options` without block arguments' do
112+
expect_no_offenses(<<~RUBY)
113+
with_options do
114+
obj.do_something
115+
end
116+
RUBY
117+
end
118+
111119
it 'does not register an offense when empty' do
112120
expect_no_offenses(<<~RUBY)
113121
with_options options: false do |merger|

0 commit comments

Comments
 (0)