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
Semantic block delimiter should allow braces on procedural one-liners #6393
Comments
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. |
option to fine-tune behavior of Style/BlockDelimiters
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 |
This would be really great. Here are examples that the semantic style that should probably use
|
@jherdman Yes, I believe that's how StandardRB behaves currently |
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. :-)
The text was updated successfully, but these errors were encountered: