Skip to content

Commit e1455c6

Browse files
whenver ther is an empty brace expression, remove line breaks
1 parent 9d076fc commit e1455c6

File tree

14 files changed

+61
-66
lines changed

14 files changed

+61
-66
lines changed

R/rules-line-breaks.R

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,21 @@ set_line_break_around_comma_and_or <- function(pd, strict) {
149149
}
150150

151151
style_line_break_around_curly <- function(strict, pd) {
152-
if (is_curly_expr(pd) && nrow(pd) > 2L) {
153-
closing_before <- pd$token == "'}'"
154-
opening_before <- (pd$token == "'{'")
155-
to_break <- lag(opening_before, default = FALSE) | closing_before
156-
pd$lag_newlines[to_break] <- ifelse(
157-
pd$token[to_break] == "COMMENT",
158-
pmin(1L, pd$lag_newlines[to_break]),
159-
if (strict) 1L else pmax(1L, pd$lag_newlines[to_break])
160-
)
152+
if (is_curly_expr(pd)) {
153+
n_row <- nrow(pd)
154+
if (n_row > 2L) {
155+
closing_before <- pd$token == "'}'"
156+
opening_before <- (pd$token == "'{'")
157+
to_break <- lag(opening_before, default = FALSE) | closing_before
158+
pd$lag_newlines[to_break] <- ifelse(
159+
pd$token[to_break] == "COMMENT",
160+
pmin(1L, pd$lag_newlines[to_break]),
161+
if (strict) 1L else pmax(1L, pd$lag_newlines[to_break])
162+
)
163+
} else if (n_row == 2L) {
164+
# pd represents {}
165+
pd$lag_newlines[2L] <- 0L
166+
}
161167
} else {
162168
is_else <- pd$token == "ELSE"
163169
if (any(pd$token_before[is_else] == "'}'")) {

tests/testthat/indention_multiple/edge_strict_mixed-out.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@
2323
)))
2424

2525

26-
function(x, y, z) {
27-
}
26+
function(x, y, z) {}

tests/testthat/indention_operators/eq_formals_complex_tokens-out.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,4 @@ function(a =
3030
f =
3131
d, c =
3232
3, d =
33-
4) {
34-
35-
}
33+
4) {}

tests/testthat/line_breaks_and_other/braces-fun-calls2-out.R

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
test(
22
"x",
3-
{
4-
5-
},
3+
{},
64
a + b,
75
{
86
s(x = sd)
@@ -11,9 +9,7 @@ test(
119

1210
test(
1311
"x",
14-
{
15-
16-
},
12+
{},
1713
a + b,
1814
{
1915
s(x = sd)
@@ -22,9 +18,7 @@ test(
2218

2319
test(
2420
"x",
25-
{
26-
27-
},
21+
{},
2822
a + b,
2923
{
3024
s(x = sd)
@@ -34,9 +28,7 @@ test(
3428

3529
test(
3630
"x",
37-
{
38-
39-
},
31+
{},
4032
a + b,
4133
{
4234
s(x = sd)
@@ -45,9 +37,7 @@ test(
4537

4638
test(
4739
"x",
48-
{
49-
50-
}, # h
40+
{}, # h
5141
a + b,
5242
{
5343
s(x = sd)
@@ -56,9 +46,7 @@ test(
5646

5747
test(
5848
"x",
59-
{
60-
61-
}, # h
49+
{}, # h
6250
a + b,
6351
# k
6452
{
@@ -68,9 +56,7 @@ test(
6856

6957
test(
7058
"x",
71-
{
72-
73-
},
59+
{},
7460
a + b, # k
7561
{
7662
s(x = sd)

tests/testthat/line_breaks_and_other/curly-in.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ while (TRUE) { }
4747

4848
while (TRUE)
4949
{ }
50+
51+
while (TRUE){
52+
53+
}
54+
55+
while (TRUE){
56+
#
57+
}
58+
59+
60+
while (TRUE){#
61+
}

tests/testthat/line_breaks_and_other/curly-out.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,13 @@ test_that(
4343
while (TRUE) {}
4444

4545
while (TRUE) {}
46+
47+
while (TRUE) {}
48+
49+
while (TRUE) {
50+
#
51+
}
52+
53+
54+
while (TRUE) { #
55+
}

tests/testthat/line_breaks_fun_call/token_dependent_complex_non_strict-out.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ call(call(
55
call(call(1,
66
2))
77
# multi-line: no indention based on first vall
8-
call(a(b(c({
9-
}))))
8+
call(a(b(c({}))))
109

1110
call(call(
1211
2),

tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ call(call(
77
2
88
))
99
# multi-line: no indention based on first vall
10-
call(a(b(c({
11-
}))))
10+
call(a(b(c({}))))
1211

1312
call(
1413
call(

tests/testthat/parse_comments/spinning_code_chunk_headers-out.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# A comment
2-
a <- function() {
3-
4-
}
2+
a <- function() {}
53

64
#+ chunk-label, opt1=value1
75
"chunk-content"
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# random
22
this(is_a_call(x))
3-
if (x) {
4-
}
3+
if (x) {}

0 commit comments

Comments
 (0)