Skip to content

Commit

Permalink
[Fix rubocop#11117] Fix a false positive for Style/BlockDelimiters
Browse files Browse the repository at this point in the history
Fixes rubocop#11117.

This PR fixes a false positive for `Style/BlockDelimiters`
when specifying `EnforcedStyle: semantic` and using a single line block
with {} followed by a safe navigation method call.
  • Loading branch information
koic committed Oct 24, 2022
1 parent 0ecaf4a commit 91a3045
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_a_false_positive_for_block_delimiters.md
@@ -0,0 +1 @@
* [#11117](https://github.com/rubocop/rubocop/issues/11117): Fix a false positive for `Style/BlockDelimiters` when specifying `EnforcedStyle: semantic` and using a single line block with {} followed by a safe navigation method call. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/block_delimiters.rb
Expand Up @@ -425,7 +425,7 @@ def return_value_used?(node)
if node.parent.begin_type?
return_value_used?(node.parent)
else
node.parent.assignment? || node.parent.send_type?
node.parent.assignment? || node.parent.call_type?
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/rubocop/cop/style/block_delimiters_spec.rb
Expand Up @@ -183,6 +183,10 @@
expect_no_offenses('detect { true }...other')
end

it 'accepts a single line block with {} followed by a safe navigation method call' do
expect_no_offenses('ary.map { |e| foo(e) }&.bar')
end

it 'accepts a multi-line functional block with do-end if it is a known procedural method' do
expect_no_offenses(<<~RUBY)
foo = bar.tap do |x|
Expand Down

0 comments on commit 91a3045

Please sign in to comment.