Skip to content

Commit

Permalink
checking for double indention must be before changing the nest's newl…
Browse files Browse the repository at this point in the history
…ines, as the result depends on nest's newlines.
  • Loading branch information
lorenzwalthert committed Jan 29, 2023
1 parent 8208348 commit 3372f00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion R/rules-line-breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,14 @@ remove_line_break_before_round_closing_after_curly <- function(pd) {

remove_line_breaks_in_fun_dec <- function(pd) {
if (is_function_declaration(pd)) {
is_double_indention <- is_double_indent_function_declaration(pd)
round_after <- (
pd$token == "')'" | pd$token_before == "'('"
) &
pd$token_before != "COMMENT"
pd$lag_newlines[pd$lag_newlines > 1L] <- 1L
pd$lag_newlines[round_after] <- 0L
if (is_double_indent_function_declaration(pd)) {
if (is_double_indention) {
pd$lag_newlines[lag(pd$token == "'('")] <- 1L
}
}
Expand Down
13 changes: 10 additions & 3 deletions tests/testthat/unindention/mixed-double-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function(
}


function(x, y) {
function(
x, y) {
1
}

Expand All @@ -70,9 +71,15 @@ function(x,


# last brace
function(x, y) NULL
function(
x, y) {
NULL
}

function(x, y) NULL
function(
x, y) {
NULL
}

function(
x,
Expand Down

0 comments on commit 3372f00

Please sign in to comment.