-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Cop idea: combine chained select
/ reject
calls
#473
Comments
It's a difficult decision, but I'm wondering if it could be possible to propose this to the Ruby Style Guide, and if the proposal passes, place it in RuboCop core with a name like |
Hm, I could see that being a style cop, too. Especially when Ruby3.4's select(&:big?).select(&:yellow?).reject(&:sweet?) could be autocorrected to select { it.big? && it.yellow? && !it.sweet? } which is arguably more legible |
Personally, I find |
|
Yep, since Ruby is a scripting language, having simplified syntax available can sometimes be convenient for users who want to write scripts. However, whether it's appropriate to use that in maintainable code should be left to the user’s discretion. Personally, I find |
maybe it could be a configuration, something like AllCops:
AutocorrectAnonymousBlockVar: it # or _1 or false to disable autocorrect for cops like |
AFAIK, autocorrection is fundamentally a supplementary tool, but it is common for autocorrected code to be reconized as correct by users. This means that cases where a named block variable is preferable could end up being replaced by For these reasons, I still remain doubt about introducing an option that enforces autocorrection to the |
Similar to how Performance/MapMethodChain combines chained
map
calls, this cop would combine multipleselect
/reject
calls into a single block expression.Benchmark:
The text was updated successfully, but these errors were encountered: