Skip to content
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

Allow parentheses in yield arguments for Style/MethodCallWithArgsParentheses #9625

Merged
merged 1 commit into from Mar 22, 2021

Conversation

gsamokovarov
Copy link
Contributor

@gsamokovarov gsamokovarov commented Mar 20, 2021

When using the omit_parentheses style, we don't recognize yield
argument calls and require parentheses omission. If we yield multiple
values, we cannot omit the parentheses in method calls as this won't be
valid Ruby. We currently register offenses for:

# Example 1
yield File.basename(path)
      ^^^^^^^^^^^^^^^^^^^ Omit parentheses for method calls with arguments.

# Correction...
yield File.basename path # 👈 This compiles.

# Example 2
yield path, File.basename(path)
            ^^^^^^^^^^^^^^^^^^^ Omit parentheses for method calls with arguments.

# Correction...
yield path, File.basename path  # 👈 This DOES NOT!!!

If we treat yield arguments as any other method call arguments, we'll
allow the parentheses and let people write valid Ruby in the cases
above.

@gsamokovarov gsamokovarov force-pushed the omit-parentheses-in-yield branch 2 times, most recently from afe7be3 to 25dd03e Compare March 20, 2021 13:49
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 22, 2021

The suggested change looks good, just move the changelog entry to the changelog folder.

…entheses`

When using the `omit_parentheses` style, we don't recognize `yield`
argument calls and require parentheses omission. If we yield multiple
values, we cannot omit the parentheses in method calls as this won't be
valid Ruby. We currently register offenses for:

```ruby
# Example 1
yield File.basename(path)
      ^^^^^^^^^^^^^^^^^^^ Omit parentheses for method calls with arguments.

# Correction...
yield File.basename path # 👈 This compiles.

# Example 2
yield path, File.basename(path)
            ^^^^^^^^^^^^^^^^^^^ Omit parentheses for method calls with arguments.

# Correction...
yield path, File.basename path # 👈 This DOES NOT!!!
```

If we treat yield arguments as any other method call arguments, we'll
allow the parentheses and let people write valid Ruby in the cases
above.
@gsamokovarov
Copy link
Contributor Author

Thanks, moved the changelog.

@bbatsov bbatsov merged commit 973188d into rubocop:master Mar 22, 2021
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 22, 2021

Thanks!

@gsamokovarov gsamokovarov deleted the omit-parentheses-in-yield branch March 23, 2021 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants