Skip to content

Commit

Permalink
[Fix #4227] Address an AmbiguousBlockAssociation false positive (#4228)
Browse files Browse the repository at this point in the history
  • Loading branch information
smakagon authored and bbatsov committed Apr 2, 2017
1 parent 022e732 commit 6414db1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [#4226](https://github.com/bbatsov/rubocop/pull/4226): Show in `--help` output that `--stdin` takes a file name argument. ([@jonas054][])
* [#4217](https://github.com/bbatsov/rubocop/pull/4217): Fix false positive in `Rails/FilePath` cop with non string argument. ([@soutaro][])
* [#4106](https://github.com/bbatsov/rubocop/pull/4106): Make `Style/TernaryParentheses` unsafe autocorrect detector aware of literals and constants. ([@drenmi][])
* [#4228](https://github.com/bbatsov/rubocop/pull/4228): Fix false positive in `Lint/AmbiguousBlockAssociation` cop. ([@smakagon][])

## 0.48.0 (2017-03-26)

Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/lint/ambiguous_block_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def on_send(node)
return if node.parenthesized? || allowed_method?(node)
return if lambda_argument?(node.first_argument)

return unless method_with_block?(node.first_argument)
first_param = node.first_argument.children.first
return unless method_as_param?(first_param)
return unless method_with_block?(node.last_argument)
last_param = node.last_argument.children.first
return unless method_as_param?(last_param)

add_offense(node, :expression, message(first_param, node.method_name))
add_offense(node, :expression, message(last_param, node.method_name))
end

private
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/lint/ambiguous_block_association_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@
it_behaves_like 'accepts', 'foo = lambda do |diagnostic|;end'
it_behaves_like 'accepts', 'Proc.new { puts "proc" }'
it_behaves_like('accepts', 'expect { order.save }.to(change { orders.size })')
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" })'
)
it_behaves_like(
'accepts',
'allow(cop).to receive(:on_int) { raise RuntimeError }'
Expand Down

0 comments on commit 6414db1

Please sign in to comment.