From 4cd001ff59ea3a8fac83afa9ac2a12011f02735f Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Thu, 8 Oct 2020 20:40:07 +0900 Subject: [PATCH] Add new "Arguments Forwarding" rule Follow https://github.com/rubocop-hq/rubocop/pull/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. # https://github.com/rubocop-hq/rubocop/issues/7549 def some_method(*args) other_method(*args) end # good def some_method(...) other_method(...) end ``` --- README.adoc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.adoc b/README.adoc index 5f77f10b7..4499ae908 100644 --- a/README.adoc +++ b/README.adoc @@ -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.