style icon indicating copy to clipboard operation
style copied to clipboard

Clarify empty braced statements

Open MichaelChirico opened this issue 2 years ago • 2 comments

The guide currently has pretty broad rules about braces:

https://style.tidyverse.org/syntax.html#indenting

One edge case apparently precluded by the current rules is an empty expression: { } or {}, for example empty while loops:

while (some_updating_condition()) { }

I don't think splitting the braces is a good choice in this case:

while (some_updating_condition()) {
}

styler already enforces what looks to me like a good rule:

library(styler)

style_text("while (TRUE) { }")
# while (TRUE) { }
style_text("while (TRUE) {}")
# while (TRUE) {}
style_text("while (TRUE) { 1 }")
# while (TRUE) {
#   1
# }

Is it worth codifying this behavior in the guide?

We are wondering how to handle this in lintr: https://github.com/r-lib/lintr/issues/1346

MichaelChirico avatar Jun 03 '22 01:06 MichaelChirico

I'm slightly leaning toward {} because it looks less like there is something missing, and it visually groups the {} closer together.

AshesITR avatar Jun 20 '22 09:06 AshesITR

FWIW rlang::expr_deparse(quote({})) is "{ }" with a space, base::deparse() inserts a line break.

moodymudskipper avatar Nov 13 '23 14:11 moodymudskipper