-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 incorrectly fixes a case where an argument is used elsewhere in the method #12089
Comments
I noticed a similar bug. Original: def post(*args, &block)
future_on(executor, *args, &block) Erroneously corrected by rubocop to: def post(...)
future_on(...) Expected behavior: def post(...)
future_on(executor, ...) |
Thanks for the report - I'll take a look at fixing this. There's clearly some overlap/similarity with #12087 too. |
FYI, I've opened #12101 to fix due to many reports about this issue. Thank you. |
Fixes rubocop#12087, rubocop#12089, rubocop#12096, and rubocop#12100. This PR fixes false positives for `Style/ArgumentsForwarding` when leading argument with rest arguments.
Additionally fixes: * rubocop#12089 * rubocop#12096 * rubocop#12100 In Ruby < 3.2 this cop was overzealous and not considering various additional args/kwargs and other reasons to not allow forward-all (`...`), and was additionally assuming that forward-all meant all arguments were replaced, which was not always the case.
1.56 included the fix (#12103) but it did not fix the issue. Source class Foo
def bar(*args, &block)
hello(*args, &block)
world(*args)
end
end Script bin/rubocop --version
1.56.0
bin/rubocop -a test.rb
Inspecting 1 file
C
Offenses:
test.rb:2:11: C: [Corrected] Style/ArgumentsForwarding: Use shorthand syntax ... for arguments forwarding.
def bar(*args, &block)
^^^^^^^^^^^^^
test.rb:3:11: C: [Corrected] Style/ArgumentsForwarding: Use shorthand syntax ... for arguments forwarding.
hello(*args, &block)
^^^^^^^^^^^^^ Output class Foo
def bar(...)
hello(...)
world(*args)
end
end Can we reopen this issue? Or let me know if opening a new issue is preferred. |
@chulkilee apologies that I've still not got the cop quite right - without looking at the code, your issue looks like a slightly different scenario/cause to me, so I think it should be a new issue. I'll try and take a look over the weekend. |
The auto-correct for the cop can break code by replacing the arguments when one of them is referenced in another part of the method.
Expected behavior
The following should not elicit a correction:
Actual behavior
It corrects to the following which throws an undefined variable error:
Steps to reproduce the problem
Auto-correct the code listed under the expected behavior heading.
RuboCop version
The text was updated successfully, but these errors were encountered: