Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ editor_options:
- `{` is not put on a new line after `=` and in `function() {` for some edge
cases (#939).

- `while ({})` statements are now handled the same way as function statements
with regards to breaking lines (#967).

- Parsing of {roxygen2} example comments now also works for edge cases when
there is no literal code immediately following after the end of the example
section (#940).
Expand Down
4 changes: 2 additions & 2 deletions R/rules-line-breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ set_line_break_before_curly_opening <- function(pd) {
~ next_terminal(pd[.x, ], vars = "token_after")$token_after
) != "'{'"
last_expr_idx <- max(which(pd$token == "expr"))
is_last_expr <- ifelse(pd$token[1] == "IF",
# rule not applicable for IF
is_last_expr <- ifelse(pd$token[1] %in% c("IF", "WHILE"),
# rule not applicable for if and while
TRUE, (line_break_to_set_idx + 1L) == last_expr_idx
)

Expand Down
26 changes: 26 additions & 0 deletions tests/testthat/line_breaks_and_other/braces-fun-calls2-in.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,29 @@ tetst(
x
}, 1 + +1
)

while ({
x
}) {
f()
}

while ({
x
}
) {
f()
}

while (
{
x
}) {
f()
}

while (
{x
}) {
f()
}
24 changes: 24 additions & 0 deletions tests/testthat/line_breaks_and_other/braces-fun-calls2-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,27 @@ tetst(
},
1 + +1
)

while ({
x
}) {
f()
}

while ({
x
}) {
f()
}

while ({
x
}) {
f()
}

while ({
x
}) {
f()
}