diff --git a/R/modify_pd.R b/R/modify_pd.R index 93bed0c89..e676fca90 100644 --- a/R/modify_pd.R +++ b/R/modify_pd.R @@ -74,8 +74,8 @@ indent_without_paren <- function(pd, indent_by = 2) { #' @describeIn update_indention Is used to indent for and while statements. indent_without_paren_for_while <- function(pd, indent_by) { nrow <- nrow(pd) - if (!(pd$token[1] %in% c("FOR", "WHILE"))) return(pd) - if (pd$lag_newlines[nrow] == 0) return(pd) + if (!(pd$token[1] %in% c("FOR", "WHILE", "FUNCTION"))) return(pd) + if (is_curly_expr(pd$child[[nrow]])) return(pd) pd$indent[nrow] <- indent_by pd } diff --git a/tests/testthat/indention_multiple/fun_for_new_line-in.R b/tests/testthat/indention_multiple/fun_for_new_line-in.R new file mode 100644 index 000000000..ff6e91449 --- /dev/null +++ b/tests/testthat/indention_multiple/fun_for_new_line-in.R @@ -0,0 +1,7 @@ +function() +NULL + +for (i in 1:3) + { +2 + } diff --git a/tests/testthat/indention_multiple/fun_for_new_line-in_tree b/tests/testthat/indention_multiple/fun_for_new_line-in_tree new file mode 100644 index 000000000..18fe7491a --- /dev/null +++ b/tests/testthat/indention_multiple/fun_for_new_line-in_tree @@ -0,0 +1,25 @@ +ROOT (token: short_text [lag_newlines/spaces] {id}) + ¦--expr: [0/0] {9} + ¦ ¦--FUNCTION: funct [0/0] {1} + ¦ ¦--'(': ( [0/0] {2} + ¦ ¦--')': ) [0/0] {3} + ¦ °--expr: [1/0] {6} + ¦ °--NULL_CONST: NULL [0/0] {5} + °--expr: [2/0] {39} + ¦--FOR: for [0/1] {14} + ¦--forcond: [0/1] {25} + ¦ ¦--'(': ( [0/0] {15} + ¦ ¦--SYMBOL: i [0/1] {16} + ¦ ¦--IN: in [0/1] {17} + ¦ ¦--expr: [0/0] {24} + ¦ ¦ ¦--expr: [0/0] {19} + ¦ ¦ ¦ °--NUM_CONST: 1 [0/0] {18} + ¦ ¦ ¦--':': : [0/0] {20} + ¦ ¦ °--expr: [0/0] {22} + ¦ ¦ °--NUM_CONST: 3 [0/0] {21} + ¦ °--')': ) [0/0] {23} + °--expr: [1/0] {36} + ¦--'{': { [0/0] {27} + ¦--expr: [1/1] {30} + ¦ °--NUM_CONST: 2 [0/0] {29} + °--'}': } [1/0] {34} diff --git a/tests/testthat/indention_multiple/fun_for_new_line-out.R b/tests/testthat/indention_multiple/fun_for_new_line-out.R new file mode 100644 index 000000000..43a7c5834 --- /dev/null +++ b/tests/testthat/indention_multiple/fun_for_new_line-out.R @@ -0,0 +1,7 @@ +function() + NULL + +for (i in 1:3) +{ + 2 +} diff --git a/tests/testthat/test-indention_multiple.R b/tests/testthat/test-indention_multiple.R index e744edd48..675333bb0 100644 --- a/tests/testthat/test-indention_multiple.R +++ b/tests/testthat/test-indention_multiple.R @@ -49,3 +49,10 @@ test_that("edge cases work", { transformer = style_text), NA) }) + +test_that("token / braces interaction works", { + expect_warning(test_collection("indention_multiple", + "fun_for_new_line", + transformer = style_text), NA) +}) +