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 #208] Update MethodDispatchNode#block_literal? to return true for numblocks #209

Merged
merged 1 commit into from Sep 28, 2021
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
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