-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Cop idea: prefer argument forwarding syntax #7549
Labels
Comments
That's a great idea and we should totally implement such a cop! |
8 tasks
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding! |
koic
added a commit
to koic/ruby-style-guide
that referenced
this issue
Oct 8, 2020
Follow rubocop/rubocop#7646. This PR adds new "Arguments Forwarding" rule that prefers Ruby 2.7's arguments forwarding syntax. ```ruby # bad def some_method(*args, &block) other_method(*args, &block) end # bad def some_method(*args, **kwargs, &block) other_method(*args, **kwargs, &block) end # bad # Please note that it can cause unexpected incompatible behavior # because `...` forwards block also. # rubocop/rubocop#7549 def some_method(*args) other_method(*args) end # good def some_method(...) other_method(...) end ```
bbatsov
pushed a commit
to rubocop/ruby-style-guide
that referenced
this issue
Oct 8, 2020
Follow rubocop/rubocop#7646. This PR adds new "Arguments Forwarding" rule that prefers Ruby 2.7's arguments forwarding syntax. ```ruby # bad def some_method(*args, &block) other_method(*args, &block) end # bad def some_method(*args, **kwargs, &block) other_method(*args, **kwargs, &block) end # bad # Please note that it can cause unexpected incompatible behavior # because `...` forwards block also. # rubocop/rubocop#7549 def some_method(*args) other_method(*args) end # good def some_method(...) other_method(...) end ```
koic
added a commit
to koic/rubocop
that referenced
this issue
Oct 22, 2020
Closes rubocop#7549. This PR adds `Style/ArgumentsForwarding` cop. As shown at rubocop#7549, the following code is unsafe to be arguments forwarding. ```ruby def foo(*args) bar(*args) end ``` So by setting `AllowOnlyRestArgument` configuration option to true by default, This PR makes the cop safe by default.
koic
added a commit
that referenced
this issue
Oct 22, 2020
[Fix #7549] Add `Style/ArgumentsForwarding` cop
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
Since Ruby 2.7, we will be able to use
...
to forward arguments to another method.I think the
...
syntax has two advantages.First, we can simply avoid keyword parameter warnings with
...
syntax.For example
Second, we can avoid missing
&block
forwarding with...
syntax.I guess many people forget passing
&block
to the forwarded method unexpectedly.But we can avoid the problem with
...
syntax.Describe the solution you'd like
Add an offense for the following code.
The last example changes the method behavior actually, so probably we should add
Strict
option to disable/enable replacing the last case.Describe alternatives you've considered
nothing
Additional context
nothing
The text was updated successfully, but these errors were encountered: