Skip to content

Commit

Permalink
Merge pull request #10567 from koic/fix_a_false_positive_for_lint_amb…
Browse files Browse the repository at this point in the history
…iguous_block_association

[Fix #10566] Fix a falase positive for `Lint/AmbiguousBlockAssociation`
  • Loading branch information
koic authored Apr 23, 2022
2 parents 548862d + a115da9 commit f6e97b4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit f6e97b4

Please # to comment.