Skip to content

Commit eaac448

Browse files
check if there is a line break anywhere before the first curly brace and if yes, also break line within curly brace
1 parent ad416b6 commit eaac448

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

R/rules-line-break.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,20 @@ set_line_break_before_curly_opening <- function(pd) {
5555
TRUE, (line_break_to_set_idx + 1L) == last_expr_idx
5656
)
5757
eq_sub_before <- pd$token[line_break_to_set_idx] == "EQ_SUB"
58+
linebreak_before_curly <- ifelse(is_function_call(pd),
59+
any(pd$lag_newlines[seq2(1, line_break_to_set_idx[1])] > 0),
60+
FALSE
61+
)
5862
# no line break before last brace expression and named brace expression to
59-
should_be_on_same_line <- is_not_curly_curly & (is_last_expr | eq_sub_before)
63+
should_be_on_same_line <- is_not_curly_curly &
64+
((is_last_expr & !linebreak_before_curly) | eq_sub_before)
6065
is_not_curly_curly_idx <- line_break_to_set_idx[should_be_on_same_line]
6166
pd$lag_newlines[1 + is_not_curly_curly_idx] <- 0L
6267

68+
6369
# other cases: line breaks
64-
should_not_be_on_same_line <- is_not_curly_curly & (!is_last_expr & !eq_sub_before)
70+
should_not_be_on_same_line <- is_not_curly_curly &
71+
((!is_last_expr | linebreak_before_curly) & !eq_sub_before)
6572
should_not_be_on_same_line_idx <- line_break_to_set_idx[should_not_be_on_same_line]
6673

6774
pd$lag_newlines[1 + should_not_be_on_same_line_idx] <- 1L

tests/testthat/curly-curly/mixed-out.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ call("test", {
6464
})
6565

6666
call(
67-
"test", {
67+
"test",
68+
{
6869
1
6970
}
7071
)

tests/testthat/indention_multiple/edge_strict_mixed-out.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
{
77
c(
88
99,
9-
1 + 1, {
9+
1 + 1,
10+
{
1011
"within that suff"
1112
}
1213
)

tests/testthat/unindention/mixed-out.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
{
88
{
99
call(
10-
call1(2, 3), {
10+
call1(2, 3),
11+
{
1112
sin(cos(pi))
1213
}
1314
)

0 commit comments

Comments
 (0)