Skip to content

Commit

Permalink
[Fix rubocop#208] Update MethodDispatchNode#block_literal? to retur…
Browse files Browse the repository at this point in the history
…n true for `numblock`s.
  • Loading branch information
dvandersluis committed Sep 15, 2021
1 parent 756d0aa commit 079352d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/fix_fix_208_update.md
@@ -0,0 +1 @@
* [#208](https://github.com/rubocop/rubocop-ast/issues/208): Update `MethodDispatchNode#block_literal?` to return true for `numblock`s. ([@dvandersluis][])
6 changes: 3 additions & 3 deletions lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Expand Up @@ -28,9 +28,9 @@ def method_name
node_parts[1]
end

# The `block` node associated with this method dispatch, if any.
# The `block` or `numblock` node associated with this method dispatch, if any.
#
# @return [BlockNode, nil] the `block` node associated with this method
# @return [BlockNode, nil] the `block` or `numblock` node associated with this method
# call or `nil`
def block_node
parent if block_literal?
Expand Down Expand Up @@ -154,7 +154,7 @@ def implicit_call?
#
# @return [Boolean] whether the dispatched method has a block
def block_literal?
parent&.block_type? && eql?(parent.send_node)
(parent&.block_type? || parent&.numblock_type?) && eql?(parent.send_node)
end

# Checks whether this node is an arithmetic operation
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/ast/send_node_spec.rb
Expand Up @@ -1034,6 +1034,14 @@ def bar

it { expect(send_node).not_to be_block_literal }
end

context 'with Ruby >= 2.7', :ruby27 do
context 'with a numblock literal' do
let(:source) { '>> foo.bar << { baz(_1) }' }

it { expect(send_node).to be_block_literal }
end
end
end

describe '#arithmetic_operation?' do
Expand Down Expand Up @@ -1074,6 +1082,14 @@ def bar

it { expect(send_node.block_node).to be_nil }
end

context 'with Ruby >= 2.7', :ruby27 do
context 'with a numblock literal' do
let(:source) { '>>foo.bar<< { baz(_1) }' }

it { expect(send_node.block_node).to be_numblock_type }
end
end
end

describe '#splat_argument?' do
Expand Down

0 comments on commit 079352d

Please sign in to comment.