Skip to content

Commit

Permalink
Add new "Arguments Forwarding" rule
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
koic committed Oct 8, 2020
1 parent 59db77d commit e48d82a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.adoc
Expand Up @@ -2841,6 +2841,36 @@ def some_method(bar: false)
end
----

=== Arguments Forwarding [[arguments-forwarding]]

Use Ruby 2.7's arguments forwarding.

[source,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.
# https://github.com/rubocop-hq/rubocop/issues/7549
def some_method(*args)
other_method(*args)
end
# good
def some_method(...)
other_method(...)
end
----

=== Private Global Methods [[private-global-methods]]

If you really need "global" methods, add them to Kernel and make them private.
Expand Down

0 comments on commit e48d82a

Please sign in to comment.