Skip to content

Commit 10f23c0

Browse files
better multi-line while() statement handling
1 parent af0e468 commit 10f23c0

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ editor_options:
2626
- `{` is not put on a new line after `=` and in `function() {` for some edge
2727
cases (#939).
2828

29+
- `while ({})` statements are now handled the same way as function statements
30+
with regards to breaking lines (#967).
31+
2932
- Parsing of {roxygen2} example comments now also works for edge cases when
3033
there is no literal code immediately following after the end of the example
3134
section (#940).

R/rules-line-breaks.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ set_line_break_before_curly_opening <- function(pd) {
6565
~ next_terminal(pd[.x, ], vars = "token_after")$token_after
6666
) != "'{'"
6767
last_expr_idx <- max(which(pd$token == "expr"))
68-
is_last_expr <- ifelse(pd$token[1] == "IF",
69-
# rule not applicable for IF
68+
is_last_expr <- ifelse(pd$token[1] %in% c("IF", "WHILE"),
69+
# rule not applicable for if and while
7070
TRUE, (line_break_to_set_idx + 1L) == last_expr_idx
7171
)
7272

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,29 @@ tetst(
7676
x
7777
}, 1 + +1
7878
)
79+
80+
while ({
81+
x
82+
}) {
83+
f()
84+
}
85+
86+
while ({
87+
x
88+
}
89+
) {
90+
f()
91+
}
92+
93+
while (
94+
{
95+
x
96+
}) {
97+
f()
98+
}
99+
100+
while (
101+
{x
102+
}) {
103+
f()
104+
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,27 @@ tetst(
8484
},
8585
1 + +1
8686
)
87+
88+
while ({
89+
x
90+
}) {
91+
f()
92+
}
93+
94+
while ({
95+
x
96+
}) {
97+
f()
98+
}
99+
100+
while ({
101+
x
102+
}) {
103+
f()
104+
}
105+
106+
while ({
107+
x
108+
}) {
109+
f()
110+
}

0 commit comments

Comments
 (0)