diff --git a/CHANGELOG.md b/CHANGELOG.md index a4d4b6b09..446eec9ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Bug fixes + +* [#237](https://github.com/rubocop/rubocop-ast/pull/237) Fix `#macro?` for numblock nodes ([@gsamokovarov][]) + ## 1.19.1 (2022-07-10) ### New features @@ -343,3 +347,4 @@ [@eugeneius]: https://github.com/eugeneius [@wcmonty]: https://github.com/wcmonty [@zverok]: https://github.com/zverok +[@gsamokovarov]: https://github.com/gsamokovarov diff --git a/lib/rubocop/ast/node/mixin/method_dispatch_node.rb b/lib/rubocop/ast/node/mixin/method_dispatch_node.rb index 98984e19b..9853d9d9e 100644 --- a/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +++ b/lib/rubocop/ast/node/mixin/method_dispatch_node.rb @@ -249,7 +249,7 @@ def binary_operation? ^{ # or the parent is... sclass class module class_constructor? # a class-like node [ { # or some "wrapper" - kwbegin begin block + kwbegin begin block numblock (if _condition <%0 _>) # note: we're excluding the condition of `if` nodes } #in_macro_scope? # that is itself in a macro scope diff --git a/spec/rubocop/ast/send_node_spec.rb b/spec/rubocop/ast/send_node_spec.rb index 4e0eeebe6..85538e2f3 100644 --- a/spec/rubocop/ast/send_node_spec.rb +++ b/spec/rubocop/ast/send_node_spec.rb @@ -167,6 +167,33 @@ module Foo it { expect(send_node).not_to be_bare_access_modifier } end + + context 'Ruby 2.7', :ruby27 do + context 'when node is access modifier in block' do + let(:source) do + <<~RUBY + included do + >> module_function << + end + RUBY + end + + it { expect(send_node).to be_bare_access_modifier } + end + + context 'when node is access modifier in numblock' do + let(:source) do + <<~RUBY + included do + _1 + >> module_function << + end + RUBY + end + + it { expect(send_node).to be_bare_access_modifier } + end + end end describe '#non_bare_access_modifier?' do @@ -275,6 +302,19 @@ module Foo it { expect(send_node).to be_macro } end + context 'Ruby 2.7', :ruby27 do + context 'when parent is a numblock in a macro scope' do + let(:source) do + ['concern :Auth do', + '>>bar :baz<<', + ' bar _1', + 'end'].join("\n") + end + + it { expect(send_node).to be_macro } + end + end + context 'when parent is a block not in a macro scope' do let(:source) { <<~RUBY } class Foo