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

Style/ArgumentsForwarding false positive #12141

Closed
benburkert opened this issue Aug 21, 2023 · 0 comments
Closed

Style/ArgumentsForwarding false positive #12141

benburkert opened this issue Aug 21, 2023 · 0 comments
Labels

Comments

@benburkert
Copy link

benburkert commented Aug 21, 2023

Given a method with a keyword argument and kwargs:

alias foo_without_bar foo

def foo(bar: nil, **opts, &blk)
  foo_without_bar(**opts, &blk)

  do_something_with(bar) unless bar.nil?
end

Expected behavior

The Style/ArgumentsForwarding cop should not trigger on this method, because replaceing bar: nil, **opts will a) include :bar in the arguments to foo_without_bar b) remove the definition of the local bar variable.

Actual behavior

The following is included in the rubocop output:

foo.rb:6:9: C: [Correctable] Style/ArgumentsForwarding: Use shorthand syntax ... for arguments forwarding.
def foo(bar: nil, **opts, &blk)
        ^^^^^^^^^^^^^^^^^^^^^^
foo.rb:7:19: C: [Correctable] Style/ArgumentsForwarding: Use shorthand syntax ... for arguments forwarding.
  foo_without_bar(**opts, &blk)
                  ^^^^^^^^^^^^

Steps to reproduce the problem

Run rubocop 1.56.1 on this file:

# frozen_string_literal: true

alias foo_without_bar foo

def foo(bar: nil, **opts, &blk)
  foo_without_bar(**opts, &blk)

  do_something_with(bar) unless bar.nil?
end

RuboCop version

$ bundle exec rubocop -V
1.56.1 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.1.4) [x86_64-darwin22]
  - rubocop-capybara 2.18.0
  - rubocop-factory_bot 2.23.1
  - rubocop-minitest 0.31.0
  - rubocop-performance 1.19.0
  - rubocop-rails 2.20.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.23.2
@koic koic closed this as completed in 81ce84f Aug 22, 2023
koic added a commit that referenced this issue Aug 22, 2023
…g_with_additional_kwarg

[Fix #12141] Fix false positive for `Style/ArgumentsForwarding`
@koic koic added the bug label Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants