style
style copied to clipboard
Clarify empty braced statements
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
I'm slightly leaning toward {}
because it looks less like there is something missing, and it visually groups the {}
closer together.
FWIW rlang::expr_deparse(quote({}))
is "{ }"
with a space, base::deparse()
inserts a line break.