Open AshesITR opened 2 years ago
It'd indeed be nice if we can support Allman style (btw, I think we should name this parameter allman_style_braces
since that's a more commonly used term AFAICT):
"if (x == y)
{
f()
}" -> code
lintr::lint(text = code, linters = lintr::all_linters())
#> <text>:2:1: style: [brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line.
#> {
#> ^
Created on 2023-12-02 with reprex v2.0.2
I love that I can just comment out the conditional statement in this style, and the code would remain syntactically valid.
It's a pity that {styler}
currently doesn't support this, but that's a different issue:
"if (x == y)
{
f()
}" -> code
styler::style_text(code)
#> if (x == y) {
#> f()
#> }
Created on 2023-12-02 with reprex v2.0.2
To enforce Allman / BSD style bracing instead of Java style bracing, i.e., all braces go on their own lines (as long as syntactically possible).
A notable exception where the R parser will throw is a top-level
else
must come on the same line as its preceding}
if there is one. Compare:Not sure how widespread BSD style bracing is in R packages, so maybe not worth adding for now until someone requests it.