Description
I've seen lots of Ruby code that uses braces around one-line blocks even when the code is not using the result of the block, i.e., when it's "procedural" rather than "functional". It's often appeared in code that was otherwise great, and I've never seen anybody object to this.
Except Rubocop. :-)
The choices of block delimiter style seem to be:
line_count_based
: One-liners have braces; everything else has do-end, even if functional.semantic
: Functional has braces; everything else has do-end, even if one-liner.braces_for_chaining
: Chained functional blocks, and one-liners, have braces; everything else has do-end, even if functional (when not chained).
There does not seem to be a choice that means "functional blocks (whether chained or not), and one-liners, have braces, even if procedural, and everything else has do-end." That is my preferred style.
What I'd like to see is that semantic
allows procedural one-liners to have braces. This may be controlled by another configuration option, or always.
Again, I'll try to Make It So myself, ideally this month to count towards a Hacktoberfest shirt. :-)
Activity
davearonson commentedon Oct 27, 2018
I've started working on this. In the interests of keeping semantic mode purely semantic, at least as an option, I'm taking the tack of making "allow braces on procedural oneliners" an additional config option.
searls commentedon Dec 3, 2018
Heads up that I roundaboutly forked and implemented this behavior in the standard gem here: https://github.com/testdouble/standard/blob/master/lib/standard/cop/semantic_blocks.rb
Would love for this (and any other) cops standard shakes loose to wind up upstream in rubocop, though. Feel free to crib from this and add to your rubocop PR
jherdman commentedon Feb 19, 2019
This would be really great. Here are examples that the semantic style that should probably use
{ }
:searls commentedon Feb 19, 2019
@jherdman Yes, I believe that's how StandardRB behaves currently