Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parenthesized forwarded args in Style/MethodCallWithArgsParentheses
The new-style arguments delegation included in Ruby 2.7 and expanded in Ruby 3.0 is required to be parenthesized, since the syntax is clashing with the endless `start...` range, which can be started with `start ...` as well. Currently, the most iffy cop of them all is issuing offenses for: ```ruby def delegated_call(...) @proxy.call(...) ^^^^^ Omit parentheses for method calls with arguments. end ``` Removing the parens will start an endless range with the beginning being the result of the method call without arguments. See the parse trees below for more details: ```bash -> ruby-parse -e "def foo(...); bar(...); end" (def :foo (args (forward-arg)) (send nil :bar (forwarded-args))) -> ruby-parse -e "def foo(...); bar ...; end" (def :foo (args (forward-arg)) (erange (send nil :bar) nil)) -> ruby-parse -e "def foo(...); bar...; end" (def :foo (args (forward-arg)) (erange (send nil :bar) nil)) ``` We don't want that so allow the parens and leave this gotcha to the poor developer that's gonna run into it.
- Loading branch information
1 parent
c8c3358
commit 93ecd7e
Showing
3 changed files
with
24 additions
and
5 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...ix_parentheses_in_forwarded_args_for_style_method_call_with_args_parentheses.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#9637](https://github.com/rubocop/rubocop/issues/9637): Allow parentheses for forwarded args in `Style/MethodCallWithArgsParentheses`'s `omit_parentheses` style to avoid endless range ambiguity. ([@gsamokovarov][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters