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 a false positive for Style/ArgumentsForwarding #12626

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
@@ -0,0 +1 @@
* [#12626](https://github.com/rubocop/rubocop/pull/12626): Fix a false positive for `Style/ArgumentsForwarding` when naming a block argument `&`. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/arguments_forwarding.rb
Expand Up @@ -291,7 +291,7 @@ def register_forward_kwargs_offense(add_parens, def_arguments_or_send, kwrest_ar
end

def register_forward_block_arg_offense(add_parens, def_arguments_or_send, block_arg)
return if target_ruby_version <= 3.0
return if target_ruby_version <= 3.0 || block_arg.source == '&'

add_offense(block_arg, message: BLOCK_MSG) do |corrector|
add_parens_if_missing(def_arguments_or_send, corrector) if add_parens
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/style/arguments_forwarding_spec.rb
Expand Up @@ -197,6 +197,14 @@ def foo(&)
RUBY
end

it 'does not register an offense when naming block arg `&`', :ruby31 do
expect_no_offenses(<<~RUBY)
def foo(&)
bar(&)
end
RUBY
end

context 'when `RedundantBlockArgumentNames: [meaningless_block_name]`' do
let(:redundant_block_argument_names) { ['meaningless_block_name'] }

Expand Down