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

[Fix #9525] Add AllowIfMethodWithArguments option to Style/SymbolProc #9535

Conversation

koic
Copy link
Member

@koic koic commented Feb 24, 2021

Summary

Fixes #9525.

This PR adds AllowIfMethodWithArguments option to Style/SymbolProc.

AllowIfMethodWithArguments: false (default)

# bad
something.do_something(foo) { |o| o.bar }

# good
something.do_something(foo, &:bar)

AllowIfMethodWithArguments: true

# good
something.do_something(foo) { |o| o.bar }

If user prefer a style that allows block for method with arguments, the user can set true to AllowIfMethodWithArguments.

Other Information

It may be possible to consider defaulting to AllowIfMethodWithArguments: true, but at the time of this patch Style/SymbolProc cop respect keeping the existing behavior.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@koic koic force-pushed the new_add_allow_if_method_has_arguments_option_to_style_symbol_proc branch from 3ec07f1 to ff273cd Compare February 24, 2021 17:05
@bbatsov
Copy link
Collaborator

bbatsov commented Feb 24, 2021

I'm fine with the proposed patch, but I think the name of the configuration option is quite confusing. AllowMethodsWith(Additional)Arguments seems a bit better to me (as you can argue that the block is an argument as well), but I'm wondering if we can do better. @rubocop-hq/rubocop-core who's best at naming here? 😆

It may be possible to consider defaulting to AllowIfMethodWithArguments: true, but at the time of this patch Style/SymbolProc cop respect keeping the existing behavior.

I'd keep the curernt default, as it has been around for ages and this is the first time I see someone unhappy with it.

@dvandersluis
Copy link
Member

👍 for AllowMethodsWithArguments. It's kind of a hard concept to name. I was thinking something like MethodsWithBlockArgumentOnly but that's clumsier IMO.

@koic koic force-pushed the new_add_allow_if_method_has_arguments_option_to_style_symbol_proc branch from ff273cd to 108f164 Compare February 25, 2021 02:31
@koic
Copy link
Member Author

koic commented Feb 25, 2021

Thank you for the feedback! I renamed the option AllowMethodsWithArguments.

I was thinking something like MethodsWithBlockArgumentOnly

I think this name is also a good candidate :-)

…ymbolProc`

## Summary

Fixes rubocop#9525.

This PR adds `AllowMethodsWithArguments` option to `Style/SymbolProc`.

### `AllowMethodsWithArguments: false` (default)

```ruby
# bad
something.do_something(foo) { |o| o.bar }

# good
something.do_something(foo, &:bar)
```

### `AllowMethodsWithArguments: true`

```ruby
# good
something.do_something(foo) { |o| o.bar }
```

If user prefer a style that allows block for method with arguments,
the user can set `true` to `AllowMethodsWithArguments`.

## Other Information

It may be possible to consider defaulting to `AllowMethodsWithArguments: true`,
but at the time of this patch `Style/SymbolProc` cop respect keeping the existing behavior.
@koic koic force-pushed the new_add_allow_if_method_has_arguments_option_to_style_symbol_proc branch from 108f164 to db955e3 Compare February 25, 2021 04:23
@bbatsov bbatsov merged commit 04019d2 into rubocop:master Feb 25, 2021
@bbatsov
Copy link
Collaborator

bbatsov commented Feb 25, 2021

Thanks!

@koic koic deleted the new_add_allow_if_method_has_arguments_option_to_style_symbol_proc branch February 25, 2021 08:03
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.

Add option to Style/SymbolProc to ignore methods with parameters
4 participants