Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #10566] Fix a false positive for Lint/AmbiguousBlockAssociation #10567

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
* [#10566](https://github.com/rubocop/rubocop/issues/10566): Fix a false positive for `Lint/AmbiguousBlockAssociation` when using proc is used as a last argument. ([@koic][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/lint/ambiguous_block_association.rb
Expand Up @@ -44,7 +44,8 @@ def on_send(node)
return unless node.arguments?

return unless ambiguous_block_association?(node)
return if node.parenthesized? || node.last_argument.lambda? || allowed_method?(node)
return if node.parenthesized? || node.last_argument.lambda? || node.last_argument.proc? ||
allowed_method?(node)

message = message(node)

Expand Down
2 changes: 2 additions & 0 deletions spec/rubocop/cop/lint/ambiguous_block_association_spec.rb
Expand Up @@ -22,6 +22,8 @@
it_behaves_like 'accepts', 'Proc.new { puts "proc" }'
it_behaves_like 'accepts', 'expect { order.save }.to(change { orders.size })'
it_behaves_like 'accepts', 'scope :active, -> { where(status: "active") }'
it_behaves_like 'accepts', 'scope :active, proc { where(status: "active") }'
it_behaves_like 'accepts', 'scope :active, Proc.new { where(status: "active") }'
it_behaves_like('accepts', 'assert_equal posts.find { |p| p.title == "Foo" }, results.first')
it_behaves_like('accepts', 'assert_equal(posts.find { |p| p.title == "Foo" }, results.first)')
it_behaves_like('accepts', 'assert_equal(results.first, posts.find { |p| p.title == "Foo" })')
Expand Down