From 4ff2473c645e73219c60afd49b0206b0d2ae6863 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 6 Dec 2024 13:59:26 +0530 Subject: [PATCH 1/8] first draft --- R/rules-line-breaks.R | 36 ++++ R/style-guides.R | 2 + .../alignment/cols-with-one-row-out.R | 25 ++- tests/testthat/alignment/fun-decs-out.R | 12 +- tests/testthat/alignment/named-out.R | 167 ++++++++++++------ tests/testthat/alignment/tribble-out.R | 6 +- tests/testthat/curly-curly/mixed-out.R | 24 ++- .../indention_multiple/curly_and_round-out.R | 6 +- .../testthat/indention_multiple/overall-out.R | 15 +- .../round_closing_on_same_line-out.R | 3 +- .../eq_formals_complex_tokens-out.R | 6 +- .../not_first_trigger-out.R | 3 +- .../multi_line-no-indention-out.R | 3 +- .../multi_line-random-out.R | 6 +- .../square_brackets_double_line_break-out.R | 6 +- .../square_brackets_line_break-out.R | 20 ++- .../line_breaks_and_other/around-eq-sub-out.R | 6 +- .../base-pipe-line-breaks-out.R | 14 +- .../braces-fun-calls1-out.R | 9 +- .../line_breaks_and_other/comma-out.R | 3 +- .../line_breaks_and_other/curly-out.R | 18 +- .../if_with_line_break_indention-out.R | 9 +- .../pipe-line-breaks-out.R | 14 +- .../line_breaks_fun_call/blank-strict-out.R | 1 - .../named_arguments-out.R | 22 ++- .../switch_ifelse_etc_no_line_break-out.R | 12 +- .../token_dependent_comments-out.R | 3 +- .../token_dependent_complex_strict-out.R | 31 +++- .../token_dependent_mixed-out.R | 21 ++- .../line_breaks_fun_call/unindent-out.R | 18 +- .../parse_comments/with_indention-out.R | 9 +- ...ltiple-function-examples-no-last-run-out.R | 3 +- .../07-roxygen-no-dontrun-out.R | 3 +- .../08-roxygen-dontrun-out.R | 3 +- .../10-styler-r-ui-out.R | 46 +++-- .../11-start-with-dontrun-out.R | 12 +- .../scope-AsIs/scope_line_breaks-out.R | 7 +- .../scope-AsIs/scope_spaces_line_breaks-out.R | 7 +- .../scope-character/scope_line_breaks-out.R | 9 +- .../scope-character/scope_tokens-out.R | 9 +- tests/testthat/strict/strict-out.R | 25 ++- tests/testthat/test-cache-high-level-api.R | 3 +- tests/testthat/test-transformers-drop.R | 1 + tests/testthat/unindention/mixed-double-out.R | 9 +- 44 files changed, 470 insertions(+), 197 deletions(-) diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 5a007bdff..215ba518e 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -453,3 +453,39 @@ set_line_breaks_between_top_level_exprs <- function(pd, allowed_blank_lines = 2L pd$lag_newlines <- pmin(pd$lag_newlines, allowed_blank_lines + 1L) pd } + + +set_line_breaks_for_multiline_args <- function(pd) { + if (!any(pd$token == "','") || any(pd$text[1L] == "tribble")) { + return(pd) + } + + has_children <- purrr::some(pd$child, purrr::negate(is.null)) + is_function_definition <- pd$token[1L] == "FUNCTION" + has_internal_linebreak <- FALSE + + if (has_children && !is_function_definition) { + children <- pd$child + idx_pre_open_brace <- which(pd$token_after == "'{'") + if (length(idx_pre_open_brace)) { + children[idx_pre_open_brace + 1] <- NULL + } + + has_internal_linebreak <- children %>% + purrr::discard(is.null) %>% + purrr::map_lgl(~ sum(.x$newlines, .x$lag_newlines) > 0L) %>% + any() + } + + if (!has_internal_linebreak && sum(pd$newlines, pd$lag_newlines) < 1L) { + return(pd) + } + + idx_comma <- which(pd$token == "','") + idx_comma_has_comment <- which(pd$token[idx_comma + 1L] == "COMMENT") + idx_comma[idx_comma_has_comment] <- idx_comma[idx_comma_has_comment] + 1L + pd[idx_comma + 1L, "lag_newlines"] <- 1L + + pd +} + diff --git a/R/style-guides.R b/R/style-guides.R index 93ea89dd2..78f7ed073 100644 --- a/R/style-guides.R +++ b/R/style-guides.R @@ -141,6 +141,8 @@ tidyverse_style <- function(scope = "tokens", if (strict) remove_line_breaks_in_fun_dec, set_line_breaks_between_top_level_exprs = if (strict) set_line_breaks_between_top_level_exprs, + set_line_breaks_for_multiline_args = + if (strict) set_line_breaks_for_multiline_args, style_line_break_around_curly = partial( style_line_break_around_curly, strict diff --git a/tests/testthat/alignment/cols-with-one-row-out.R b/tests/testthat/alignment/cols-with-one-row-out.R index 30893a93e..5b2af5fc1 100644 --- a/tests/testthat/alignment/cols-with-one-row-out.R +++ b/tests/testthat/alignment/cols-with-one-row-out.R @@ -1,16 +1,29 @@ c( - "x", "z", - "cgjhg", "thi", "z" + "x", + "z", + "cgjhg", + "thi", + "z" ) c( - "x", "z", - "cgjhg", "thi", "z" + "x", + "z", + "cgjhg", + "thi", + "z" ) c( - "x", "y", "z", "m", "n", "o", "p", - "c", "d" + "x", + "y", + "z", + "m", + "n", + "o", + "p", + "c", + "d" ) diff --git a/tests/testthat/alignment/fun-decs-out.R b/tests/testthat/alignment/fun-decs-out.R index fcefee559..b64ae4e0d 100644 --- a/tests/testthat/alignment/fun-decs-out.R +++ b/tests/testthat/alignment/fun-decs-out.R @@ -28,11 +28,15 @@ k <- function(x = fish, # aligned k <- function(x = flus(we), - aq = x - 22, k = 22, - ayz = m(jk5), xfea = 3) {} + aq = x - 22, + k = 22, + ayz = m(jk5), + xfea = 3) {} # aligned k <- function(x = flus(we), - aq = x - 22, k = 22, - ayz = m(jk5), xfea = 3) {} + aq = x - 22, + k = 22, + ayz = m(jk5), + xfea = 3) {} diff --git a/tests/testthat/alignment/named-out.R b/tests/testthat/alignment/named-out.R index 35c3bb607..7fe5b0ab6 100644 --- a/tests/testthat/alignment/named-out.R +++ b/tests/testthat/alignment/named-out.R @@ -1,104 +1,140 @@ # algorithm: aligned. human: aligned. call( - x = 1, kdd = 2, - xy = 2, n = 33, + x = 1, + kdd = 2, + xy = 2, + n = 33, ) # without trailing comma call( - x = 1, kdd = 2, - xy = 2, n = 33 + x = 1, + kdd = 2, + xy = 2, + n = 33 ) # algorithm: aligned. human: aligned. call( - x = 1, kdd = 2, - xy = 2, n = 33, + x = 1, + kdd = 2, + xy = 2, + n = 33, ) # algorithm: aligned. human: aligned. call( - x = 1, kdd = 2, - xy = 2, n = 33, + x = 1, + kdd = 2, + xy = 2, + n = 33, ) # algorithm: not aligned (spacing around =). human: aligned (fix: spacing around =). call( - x = 1, kdd = 2, - xy = 2, n = 33, + x = 1, + kdd = 2, + xy = 2, + n = 33, ) # algorithm: not aligned. human: not aligned. call( - x = 1, kdd = 2, - xy = 2, n = 33, + x = 1, + kdd = 2, + xy = 2, + n = 33, ) # algorithm: not aligned. human: not aligned. call( - x = 1, kdd = 2, - xy = 22, n = 33, + x = 1, + kdd = 2, + xy = 22, + n = 33, ) # algorithm: not aligned. human: not aligned. call( - x = 1, d = 2, - xy = 22, n = 33, + x = 1, + d = 2, + xy = 22, + n = 33, ) # algorithm: aligned. human: aligned. call( - x = 1, kdd = 2, k = "abc", - xy = 2, n = 33, z = "333" + x = 1, + kdd = 2, + k = "abc", + xy = 2, + n = 33, + z = "333" ) # algorithm: aligned. human: aligned. call( - x = 1, - xy = 2, n = 33, z = "333" + x = 1, + xy = 2, + n = 33, + z = "333" ) # algorithm: aligned. human: aligned. call( - x = 1, n = 33, z = "333", + x = 1, + n = 33, + z = "333", xy = 2, ) # aligned. when spaces are spread accross different nests call( - k = ff("pk"), k = 3, - b = f(-g), 22 + 1, - 44, 323 + k = ff("pk"), + k = 3, + b = f(-g), + 22 + 1, + 44, + 323 ) # aligned. when spaces are spread accross different nests call( - k = ff("pk"), k = 3, - b = f(-g), 22 + 1, - 44, 323, + k = ff("pk"), + k = 3, + b = f(-g), + 22 + 1, + 44, + 323, ) # no trailing call( - k = ff("pk"), k = 3, - b = f(-g), 22 + 1, + k = ff("pk"), + k = 3, + b = f(-g), + 22 + 1, 44 ) # aligned: fewest arguments not on last line call( 44, - k = ff("pk"), k = 3, - b = f(-g), 22 + 1, + k = ff("pk"), + k = 3, + b = f(-g), + 22 + 1, ) # aligned: fewest arguments not on last line call( - k = ff("pk"), k = 3, + k = ff("pk"), + k = 3, 44, - b = f(-g), 22 + 1, + b = f(-g), + 22 + 1, ) @@ -126,41 +162,47 @@ call( # aligned (comments) call( - a = 2, x = 111, + a = 2, + x = 111, # another - bb = 3, # hi + bb = 3, # hi ) # aligned (comments) call( - a = 2, x = 111, - bb = 3, # hi + a = 2, + x = 111, + bb = 3, # hi ) # aligned (comments) call( # another one - a = 2, x = 111, - bb = 3, # hi + a = 2, + x = 111, + bb = 3, # hi ) # aligned (comments) call( # another one - a = 2, x = 111, - bb = 3 # hi + a = 2, + x = 111, + bb = 3 # hi ) # not aligned (comments) call( - a = 2, x = 111, + a = 2, + x = 111, bb = 3, # hi ) # not aligned (comments) call( # another one - a = 2, x = 111, + a = 2, + x = 111, bb = 3, # hi ) @@ -191,30 +233,45 @@ ca( # aligned =, first all named fell( - x = 8, annoying = 3, - y = 23, # nothing in column 2 for row 2 - zz = NULL, finally = "stuff" + x = 8, + annoying = 3, + y = 23, # nothing in column 2 for row 2 + zz = NULL, + finally = "stuff" ) # aligned =, first not all named gell( - p = 2, g = gg(x), n = 3 * 3, # - 31, fds = -1, gz = f / 3 + 1, + p = 2, + g = gg(x), + n = 3 * 3, # + 31, + fds = -1, + gz = f / 3 + 1, ) xgle( - 1212, 232, f(n = 2), - 1, 2, "kFlya" + 1212, + 232, + f(n = 2), + 1, + 2, + "kFlya" ) # left aligned after , call( - x = 2, y = "another", - y = "hhjkjkbew", x = 3 + x = 2, + y = "another", + y = "hhjkjkbew", + x = 3 ) call( - k = ff("pk"), k = 3, - b = f(-g), 22 + 1, - 44, 323 + k = ff("pk"), + k = 3, + b = f(-g), + 22 + 1, + 44, + 323 ) diff --git a/tests/testthat/alignment/tribble-out.R b/tests/testthat/alignment/tribble-out.R index 2e618487e..8a7678124 100644 --- a/tests/testthat/alignment/tribble-out.R +++ b/tests/testthat/alignment/tribble-out.R @@ -25,6 +25,8 @@ tribble( # has EQ_SUB which don't match, not tribble-like mlr3misc:::rowwise_table( - x = 23, zy = 3, - y = 1, k = 1, + x = 23, + zy = 3, + y = 1, + k = 1, ) diff --git a/tests/testthat/curly-curly/mixed-out.R b/tests/testthat/curly-curly/mixed-out.R index a18134391..31cbe3e00 100644 --- a/tests/testthat/curly-curly/mixed-out.R +++ b/tests/testthat/curly-curly/mixed-out.R @@ -69,13 +69,19 @@ call( } ) -call("test", { - 1 -}) +call( + "test", + { + 1 + } +) -call("test", { - 1 -}) +call( + "test", + { + 1 + } +) call( { @@ -90,12 +96,14 @@ call( call({{ x }}, {{ y }}) call({{ x }}, {{ y }}) call( - {{ x }}, {{ y }} + {{ x }}, + {{ y }} ) call( {{ x }}, - {{ y }} := 3, f(bk) + {{ y }} := 3, + f(bk) ) call({{ diff --git a/tests/testthat/indention_multiple/curly_and_round-out.R b/tests/testthat/indention_multiple/curly_and_round-out.R index f8a4acad2..584580b1a 100644 --- a/tests/testthat/indention_multiple/curly_and_round-out.R +++ b/tests/testthat/indention_multiple/curly_and_round-out.R @@ -5,7 +5,8 @@ test_that("this is a text", { (({ { call( - 12, 1 + 1, + 12, + 1 + 1, 26 ) } @@ -15,7 +16,8 @@ test_that("this is a text", { (({ { call( - 12, 1 + 1, + 12, + 1 + 1, 26 ) } diff --git a/tests/testthat/indention_multiple/overall-out.R b/tests/testthat/indention_multiple/overall-out.R index 4db2b90fc..860d79497 100644 --- a/tests/testthat/indention_multiple/overall-out.R +++ b/tests/testthat/indention_multiple/overall-out.R @@ -4,9 +4,12 @@ #' indented comments a <- function(x) { test_that("I want to test", { - out <- c(1, c( - 22 + 1 - )) + out <- c( + 1, + c( + 22 + 1 + ) + ) if (x > 10) { for (x in 22) { # FIXME in operator only to be surrounded by one space. What about %in%? prin(x) @@ -24,8 +27,10 @@ a <- function(x) { ) call( - 1, 2, - 23 + Inf - 99, call( + 1, + 2, + 23 + Inf - 99, + call( 16 ) ) diff --git a/tests/testthat/indention_multiple/round_closing_on_same_line-out.R b/tests/testthat/indention_multiple/round_closing_on_same_line-out.R index 52487327d..af183aac3 100644 --- a/tests/testthat/indention_multiple/round_closing_on_same_line-out.R +++ b/tests/testthat/indention_multiple/round_closing_on_same_line-out.R @@ -1,4 +1,5 @@ c( - call(2), 1, # comment + call(2), + 1, # comment 29 ) diff --git a/tests/testthat/indention_operators/eq_formals_complex_tokens-out.R b/tests/testthat/indention_operators/eq_formals_complex_tokens-out.R index 9c001e666..c6d879642 100644 --- a/tests/testthat/indention_operators/eq_formals_complex_tokens-out.R +++ b/tests/testthat/indention_operators/eq_formals_complex_tokens-out.R @@ -33,6 +33,8 @@ function( function(a = b, f = - d, c = - 3, d = + d, + c = + 3, + d = 4) {} diff --git a/tests/testthat/indention_operators/not_first_trigger-out.R b/tests/testthat/indention_operators/not_first_trigger-out.R index c5569c8ce..3bb5db512 100644 --- a/tests/testthat/indention_operators/not_first_trigger-out.R +++ b/tests/testthat/indention_operators/not_first_trigger-out.R @@ -4,7 +4,8 @@ j() a <- c( - x, y, + x, + y, z ) %>% k() diff --git a/tests/testthat/indention_round_brackets/multi_line-no-indention-out.R b/tests/testthat/indention_round_brackets/multi_line-no-indention-out.R index e960a3d0d..99ec45a29 100644 --- a/tests/testthat/indention_round_brackets/multi_line-no-indention-out.R +++ b/tests/testthat/indention_round_brackets/multi_line-no-indention-out.R @@ -1,7 +1,8 @@ call( 1, call2( - 2, 3, + 2, + 3, call3(1, 2, 22), 5 ), diff --git a/tests/testthat/indention_round_brackets/multi_line-random-out.R b/tests/testthat/indention_round_brackets/multi_line-random-out.R index 98b2950bd..708ab28a4 100644 --- a/tests/testthat/indention_round_brackets/multi_line-random-out.R +++ b/tests/testthat/indention_round_brackets/multi_line-random-out.R @@ -1,7 +1,8 @@ call( 1, call2( - 2, 3, + 2, + 3, call3(1, 2, 22), 5 ), @@ -11,7 +12,8 @@ call( call( 1, call2( - 2, 3, + 2, + 3, call3(1, 2, 22), 5 ), diff --git a/tests/testthat/indention_square_brackets/square_brackets_double_line_break-out.R b/tests/testthat/indention_square_brackets/square_brackets_double_line_break-out.R index 378cb936b..15edbe553 100644 --- a/tests/testthat/indention_square_brackets/square_brackets_double_line_break-out.R +++ b/tests/testthat/indention_square_brackets/square_brackets_double_line_break-out.R @@ -29,8 +29,10 @@ a[[ a[[ # this comment shouldn't mess - 1, c( - 1, 2 + 1, + c( + 1, + 2 # neither should this one ) diff --git a/tests/testthat/indention_square_brackets/square_brackets_line_break-out.R b/tests/testthat/indention_square_brackets/square_brackets_line_break-out.R index f888e3398..505f89ca3 100644 --- a/tests/testthat/indention_square_brackets/square_brackets_line_break-out.R +++ b/tests/testthat/indention_square_brackets/square_brackets_line_break-out.R @@ -16,17 +16,23 @@ fac[ ] fac[ - , `:`(a = b) + , + `:`(a = b) ] fac[ - , `:`(a = b) + , + `:`(a = b) ] -fac[, `:`(a = c)] +fac[ + , + `:`(a = c) +] fac[ - , `:`(a = c) + , + `:`(a = c) ] x[a == 3 | @@ -68,8 +74,10 @@ x[ x[ # this comment shouldn't be an issue - 1, c( - 1, 2 + 1, + c( + 1, + 2 # neither should this one ) diff --git a/tests/testthat/line_breaks_and_other/around-eq-sub-out.R b/tests/testthat/line_breaks_and_other/around-eq-sub-out.R index 29fe9894c..acc545e2d 100644 --- a/tests/testthat/line_breaks_and_other/around-eq-sub-out.R +++ b/tests/testthat/line_breaks_and_other/around-eq-sub-out.R @@ -28,12 +28,14 @@ c( c( - b = 4, x # comment + b = 4, + x # comment = 2 ) c( x = # comment - 2, c = + 2, + c = ) diff --git a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R index 346e0303c..68ecb22f8 100644 --- a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R +++ b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R @@ -76,12 +76,18 @@ fun( ) # FIXME closing brace could go on ntext line. Alternative: remove lin breaks completely. -blew(x |> - c(), y = 2) +blew( + x |> + c(), + y = 2 +) # FIXME closing brace could go on ntext line. Alternative: move c() up. -blew(y = 2, x |> - c()) +blew( + y = 2, + x |> + c() +) { diff --git a/tests/testthat/line_breaks_and_other/braces-fun-calls1-out.R b/tests/testthat/line_breaks_and_other/braces-fun-calls1-out.R index df9b2137d..82f51f060 100644 --- a/tests/testthat/line_breaks_and_other/braces-fun-calls1-out.R +++ b/tests/testthat/line_breaks_and_other/braces-fun-calls1-out.R @@ -3,9 +3,12 @@ test_that(x, { hh }) -test_that(x, { - hh -}) +test_that( + x, + { + hh + } +) # there are multiple brace expressions that spread over multiple lines diff --git a/tests/testthat/line_breaks_and_other/comma-out.R b/tests/testthat/line_breaks_and_other/comma-out.R index 14842c18e..1cde3fd9c 100644 --- a/tests/testthat/line_breaks_and_other/comma-out.R +++ b/tests/testthat/line_breaks_and_other/comma-out.R @@ -5,7 +5,8 @@ call( ) call( - a, b, + a, + b, c ) diff --git a/tests/testthat/line_breaks_and_other/curly-out.R b/tests/testthat/line_breaks_and_other/curly-out.R index 22730a44b..4a1fa2f26 100644 --- a/tests/testthat/line_breaks_and_other/curly-out.R +++ b/tests/testthat/line_breaks_and_other/curly-out.R @@ -5,9 +5,12 @@ if (y == 0) { 2 } -test_that("I am here", { - a_test(x) -}) +test_that( + "I am here", + { + a_test(x) + } +) # A { should always be followed by a new line @@ -27,9 +30,12 @@ if (1 > 3) { "y" } -test_that("I am here", { - a_test(x) -}) +test_that( + "I am here", + { + a_test(x) + } +) test_that( desc = "bla", diff --git a/tests/testthat/line_breaks_and_other/if_with_line_break_indention-out.R b/tests/testthat/line_breaks_and_other/if_with_line_break_indention-out.R index 1bd955003..46eddced9 100644 --- a/tests/testthat/line_breaks_and_other/if_with_line_break_indention-out.R +++ b/tests/testthat/line_breaks_and_other/if_with_line_break_indention-out.R @@ -6,6 +6,9 @@ if (x) { } # removing line-break -test_that("x", { - my_test(call) -}) +test_that( + "x", + { + my_test(call) + } +) diff --git a/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R b/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R index 093655a80..f86c70d11 100644 --- a/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R +++ b/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R @@ -81,12 +81,18 @@ fun( ) # FIXME closing brace could go on ntext line. Alternative: remove lin breaks completely. -blew(x %>% - c(), y = 2) +blew( + x %>% + c(), + y = 2 +) # FIXME closing brace could go on ntext line. Alternative: move c() up. -blew(y = 2, x %>% - c()) +blew( + y = 2, + x %>% + c() +) { diff --git a/tests/testthat/line_breaks_fun_call/blank-strict-out.R b/tests/testthat/line_breaks_fun_call/blank-strict-out.R index 19232c9fa..fd67726ef 100644 --- a/tests/testthat/line_breaks_fun_call/blank-strict-out.R +++ b/tests/testthat/line_breaks_fun_call/blank-strict-out.R @@ -20,7 +20,6 @@ call( # comment - 1, 2, 3 diff --git a/tests/testthat/line_breaks_fun_call/named_arguments-out.R b/tests/testthat/line_breaks_fun_call/named_arguments-out.R index 485e4d609..e074a7047 100644 --- a/tests/testthat/line_breaks_fun_call/named_arguments-out.R +++ b/tests/testthat/line_breaks_fun_call/named_arguments-out.R @@ -1,5 +1,6 @@ call(3, - b = 2, c + b = 2, + c ) gs(3, @@ -9,16 +10,25 @@ gs(3, call(3, b = 2, c) -map(data, fun, - x = 3, z = 33 +map(data, + fun, + x = 3, + z = 33 ) map2( - dat1, data2, fun, x, y, + dat1, + data2, + fun, + x, + y, z ) -map2(dat1, data2, fun, - x = 1, y = 2, +map2(dat1, + data2, + fun, + x = 1, + y = 2, z ) diff --git a/tests/testthat/line_breaks_fun_call/switch_ifelse_etc_no_line_break-out.R b/tests/testthat/line_breaks_fun_call/switch_ifelse_etc_no_line_break-out.R index f43cd21f8..074b50b6f 100644 --- a/tests/testthat/line_breaks_fun_call/switch_ifelse_etc_no_line_break-out.R +++ b/tests/testthat/line_breaks_fun_call/switch_ifelse_etc_no_line_break-out.R @@ -48,11 +48,13 @@ switch(x, ) if_else(a, - c, v + c, + v ) ifelse(x, - y, z + y, + z ) @@ -68,10 +70,12 @@ base::switch(f, ) dplyr::ifelse(x, - 1, 32 + 1, + 32 ) dplyr::ifelse( x, - 1, 32 + 1, + 32 ) diff --git a/tests/testthat/line_breaks_fun_call/token_dependent_comments-out.R b/tests/testthat/line_breaks_fun_call/token_dependent_comments-out.R index 68cb70a94..c3aa80b64 100644 --- a/tests/testthat/line_breaks_fun_call/token_dependent_comments-out.R +++ b/tests/testthat/line_breaks_fun_call/token_dependent_comments-out.R @@ -1,5 +1,6 @@ call(call( # comment - 3, 4 + 3, + 4 )) call(call( diff --git a/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R b/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R index 8e0309e98..72add0b92 100644 --- a/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R +++ b/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R @@ -19,19 +19,29 @@ call( call(call( 1, - 2, c( + 2, + c( 3 ) )) call( 1, - call2(3, 4, call( + call2( 3, - 4, call(5, 6, call( - 2 - )) - )) + 4, + call( + 3, + 4, + call( + 5, + 6, + call( + 2 + ) + ) + ) + ) ) # comment lala @@ -40,6 +50,9 @@ call(call( 2 )) -call(1, call( - 23 -)) +call( + 1, + call( + 23 + ) +) diff --git a/tests/testthat/line_breaks_fun_call/token_dependent_mixed-out.R b/tests/testthat/line_breaks_fun_call/token_dependent_mixed-out.R index 1bd68278f..5cfcb6160 100644 --- a/tests/testthat/line_breaks_fun_call/token_dependent_mixed-out.R +++ b/tests/testthat/line_breaks_fun_call/token_dependent_mixed-out.R @@ -1,16 +1,19 @@ call(call( - call3(), call, + call3(), + call, 4433, 55 )) call(call( - call3(), call, + call3(), + call, 4433, 55 )) call(call( - call3(), call, + call3(), + call, 4433, 55 )) @@ -18,7 +21,8 @@ call(call( # no more barcket on same line -> call(call( - 3, 4 + 3, + 4 )) @@ -29,7 +33,8 @@ call( call(call( - call3(), call, + call3(), + call, 44, 55 )) @@ -37,13 +42,15 @@ call(call( # call( - call, call(), + call, + call(), 3, 4 ) call(call( - 3, 4 + 3, + 4 )) call(call( diff --git a/tests/testthat/line_breaks_fun_call/unindent-out.R b/tests/testthat/line_breaks_fun_call/unindent-out.R index 6452a6c74..2c05c02ae 100644 --- a/tests/testthat/line_breaks_fun_call/unindent-out.R +++ b/tests/testthat/line_breaks_fun_call/unindent-out.R @@ -1,6 +1,9 @@ -test_that(key( - s -), x = 1) +test_that( + key( + s + ), + x = 1 +) test_that( key( @@ -10,9 +13,12 @@ test_that( ) -test_that(key( - s -), x = 1) +test_that( + key( + s + ), + x = 1 +) test_that( diff --git a/tests/testthat/parse_comments/with_indention-out.R b/tests/testthat/parse_comments/with_indention-out.R index 526802374..c9cf55335 100644 --- a/tests/testthat/parse_comments/with_indention-out.R +++ b/tests/testthat/parse_comments/with_indention-out.R @@ -2,12 +2,15 @@ call( 1, call2( - 2, 3, + 2, + 3, call3( # zero # one # two2 - 1, 2 # two - , 22 # comment + 1, + 2 # two + , + 22 # comment ), 5 ), #' A roxygen comment diff --git a/tests/testthat/roxygen-examples-complete/06-multiple-function-examples-no-last-run-out.R b/tests/testthat/roxygen-examples-complete/06-multiple-function-examples-no-last-run-out.R index edda23f97..79ca7599a 100644 --- a/tests/testthat/roxygen-examples-complete/06-multiple-function-examples-no-last-run-out.R +++ b/tests/testthat/roxygen-examples-complete/06-multiple-function-examples-no-last-run-out.R @@ -4,7 +4,8 @@ #' Carefully examine the results after running this function! #' @examples style_pkg( #' style = -#' tidyverse_style, strict = TRUE +#' tidyverse_style, +#' strict = TRUE #' ) #' @name k a <- 2 diff --git a/tests/testthat/roxygen-examples-complete/07-roxygen-no-dontrun-out.R b/tests/testthat/roxygen-examples-complete/07-roxygen-no-dontrun-out.R index 993d3eaa3..6ac7cee18 100644 --- a/tests/testthat/roxygen-examples-complete/07-roxygen-no-dontrun-out.R +++ b/tests/testthat/roxygen-examples-complete/07-roxygen-no-dontrun-out.R @@ -15,7 +15,8 @@ #' xfun::write_utf8("1++1", file) #' style_file( #' file, -#' style = tidyverse_style, strict = TRUE +#' style = tidyverse_style, +#' strict = TRUE #' ) #' style_file(file, transformers = tidyverse_style(strict = TRUE)) #' xfun::read_utf8(file) diff --git a/tests/testthat/roxygen-examples-complete/08-roxygen-dontrun-out.R b/tests/testthat/roxygen-examples-complete/08-roxygen-dontrun-out.R index 8e92f97cd..6fd7ffbee 100644 --- a/tests/testthat/roxygen-examples-complete/08-roxygen-dontrun-out.R +++ b/tests/testthat/roxygen-examples-complete/08-roxygen-dontrun-out.R @@ -17,7 +17,8 @@ #' } #' style_file( #' file, -#' style = tidyverse_style, strict = TRUE +#' style = tidyverse_style, +#' strict = TRUE #' ) #' style_file(file, transformers = tidyverse_style(strict = TRUE)) #' xfun::read_utf8(file) diff --git a/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R b/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R index a7cbf3aca..a6e26b5d9 100644 --- a/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R +++ b/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R @@ -73,9 +73,15 @@ style_pkg <- function(pkg = ".", exclude_files = "R/RcppExports.R", include_roxygen_examples = TRUE) { pkg_root <- rprojroot::find_package_root_file(path = pkg) - changed <- withr::with_dir(pkg_root, prettify_pkg( - transformers, filetype, exclude_files, include_roxygen_examples - )) + changed <- withr::with_dir( + pkg_root, + prettify_pkg( + transformers, + filetype, + exclude_files, + include_roxygen_examples + ) + ) invisible(changed) } @@ -88,15 +94,21 @@ prettify_pkg <- function(transformers, if ("\\.r" %in% filetype) { r_files <- dir( - path = c("R", "tests", "data-raw"), pattern = "\\.r$", - ignore.case = TRUE, recursive = TRUE, full.names = TRUE + path = c("R", "tests", "data-raw"), + pattern = "\\.r$", + ignore.case = TRUE, + recursive = TRUE, + full.names = TRUE ) } if ("\\.rmd" %in% filetype) { vignette_files <- dir( - path = "vignettes", pattern = "\\.rmd$", - ignore.case = TRUE, recursive = TRUE, full.names = TRUE + path = "vignettes", + pattern = "\\.rmd$", + ignore.case = TRUE, + recursive = TRUE, + full.names = TRUE ) readme <- dir(pattern = "^readme\\.rmd$", ignore.case = TRUE) } @@ -159,8 +171,13 @@ style_dir <- function(path = ".", exclude_files = NULL, include_roxygen_examples = TRUE) { changed <- withr::with_dir( - path, prettify_any( - transformers, filetype, recursive, exclude_files, include_roxygen_examples + path, + prettify_any( + transformers, + filetype, + recursive, + exclude_files, + include_roxygen_examples ) ) invisible(changed) @@ -179,11 +196,16 @@ prettify_any <- function(transformers, exclude_files, include_roxygen_examples) { files <- dir( - path = ".", pattern = map_filetype_to_pattern(filetype), - ignore.case = TRUE, recursive = recursive, full.names = TRUE + path = ".", + pattern = map_filetype_to_pattern(filetype), + ignore.case = TRUE, + recursive = recursive, + full.names = TRUE ) transform_files( - setdiff(files, exclude_files), transformers, include_roxygen_examples + setdiff(files, exclude_files), + transformers, + include_roxygen_examples ) } diff --git a/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R b/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R index 35a804639..8624e2a08 100644 --- a/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R +++ b/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R @@ -18,8 +18,14 @@ style_pkg <- function(pkg = ".", exclude_files = "R/RcppExports.R", include_roxygen_examples = TRUE) { pkg_root <- rprojroot::find_package_root_file(path = pkg) - changed <- withr::with_dir(pkg_root, prettify_pkg( - transformers, filetype, exclude_files, include_roxygen_examples - )) + changed <- withr::with_dir( + pkg_root, + prettify_pkg( + transformers, + filetype, + exclude_files, + include_roxygen_examples + ) + ) invisible(changed) } diff --git a/tests/testthat/scope-AsIs/scope_line_breaks-out.R b/tests/testthat/scope-AsIs/scope_line_breaks-out.R index c5dd80a84..968e805eb 100644 --- a/tests/testthat/scope-AsIs/scope_line_breaks-out.R +++ b/tests/testthat/scope-AsIs/scope_line_breaks-out.R @@ -6,9 +6,12 @@ if (x) { } # removing line-break -test_that("x", { +test_that( +"x", + { my_test(call) - }) + } +) # do not replace assignment diff --git a/tests/testthat/scope-AsIs/scope_spaces_line_breaks-out.R b/tests/testthat/scope-AsIs/scope_spaces_line_breaks-out.R index 721ffc0af..968e805eb 100644 --- a/tests/testthat/scope-AsIs/scope_spaces_line_breaks-out.R +++ b/tests/testthat/scope-AsIs/scope_spaces_line_breaks-out.R @@ -6,9 +6,12 @@ if (x) { } # removing line-break -test_that("x", { +test_that( +"x", + { my_test(call) - }) + } +) # do not replace assignment diff --git a/tests/testthat/scope-character/scope_line_breaks-out.R b/tests/testthat/scope-character/scope_line_breaks-out.R index 6a8af3216..b4e1a8675 100644 --- a/tests/testthat/scope-character/scope_line_breaks-out.R +++ b/tests/testthat/scope-character/scope_line_breaks-out.R @@ -6,9 +6,12 @@ if (x) { } # removing line-break -test_that("x", { - my_test(call) -}) +test_that( + "x", + { + my_test(call) + } +) # do not replace assignment diff --git a/tests/testthat/scope-character/scope_tokens-out.R b/tests/testthat/scope-character/scope_tokens-out.R index 22b26a9cf..11c32de5d 100644 --- a/tests/testthat/scope-character/scope_tokens-out.R +++ b/tests/testthat/scope-character/scope_tokens-out.R @@ -6,9 +6,12 @@ if (x) { } # removing line-break -test_that("x", { - my_test(call) -}) +test_that( + "x", + { + my_test(call) + } +) # do not replace assignment diff --git a/tests/testthat/strict/strict-out.R b/tests/testthat/strict/strict-out.R index 688cf7f88..932b5239d 100644 --- a/tests/testthat/strict/strict-out.R +++ b/tests/testthat/strict/strict-out.R @@ -82,9 +82,12 @@ test <- function() { # Only with conservative settings: call( - preserves, distance, - after, commas, - given_has, one + preserves, + distance, + after, + commas, + given_has, + one ) if (TRUE) { @@ -104,14 +107,16 @@ test <- function() { single_line("function", call) multiline( - "function", call + "function", + call ) nested(function_call("in", one, line)) nested(function_call( "in", - multiple, lines + multiple, + lines )) nested( @@ -123,14 +128,18 @@ test <- function() { nested( function_call(with), # a comment and many # more - , first_level_args + , + first_level_args ) difficult( nested( - "function", call + "function", + call ), - with, more, args + with, + more, + args ) } diff --git a/tests/testthat/test-cache-high-level-api.R b/tests/testthat/test-cache-high-level-api.R index e645f8bc8..306d41f32 100644 --- a/tests/testthat/test-cache-high-level-api.R +++ b/tests/testthat/test-cache-high-level-api.R @@ -190,7 +190,8 @@ test_that("avoid removing roxygen mask (see commit messages in #584)", { "#'", "#' @examples", "#' c(", - "#' 1, 2,", + "#' 1,", + "#' 2,", "#' x - 2", "#' )", "#' x", diff --git a/tests/testthat/test-transformers-drop.R b/tests/testthat/test-transformers-drop.R index ad10908f5..42030f7cd 100644 --- a/tests/testthat/test-transformers-drop.R +++ b/tests/testthat/test-transformers-drop.R @@ -73,6 +73,7 @@ test_that("tidyverse transformers are correctly dropped", { names_line_break <- c( "remove_empty_lines_after_opening_and_before_closing_braces", "set_line_breaks_between_top_level_exprs", + "set_line_breaks_for_multiline_args", "set_line_break_around_comma_and_or", "set_line_break_after_assignment", "set_line_break_after_opening_if_call_is_multi_line", diff --git a/tests/testthat/unindention/mixed-double-out.R b/tests/testthat/unindention/mixed-double-out.R index 44591e1f2..c5c9068ef 100644 --- a/tests/testthat/unindention/mixed-double-out.R +++ b/tests/testthat/unindention/mixed-double-out.R @@ -62,7 +62,8 @@ function( function( - x, y + x, + y ) { 1 } @@ -76,12 +77,14 @@ function(x, # last brace function( - x, y) { + x, + y) { NULL } function( - x, y) { + x, + y) { NULL } From eba5ca198ddf757fba508f26645a740af4d441b3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 6 Dec 2024 08:31:07 +0000 Subject: [PATCH 2/8] pre-commit --- R/rules-line-breaks.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 215ba518e..51a2bf08b 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -488,4 +488,3 @@ set_line_breaks_for_multiline_args <- function(pd) { pd } - From f0a4183c20cb5bb866ffa745236cf4bf756b25fd Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 6 Dec 2024 14:18:53 +0530 Subject: [PATCH 3/8] Update rules-line-breaks.R --- R/rules-line-breaks.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 215ba518e..c3bf1a8cf 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -468,7 +468,7 @@ set_line_breaks_for_multiline_args <- function(pd) { children <- pd$child idx_pre_open_brace <- which(pd$token_after == "'{'") if (length(idx_pre_open_brace)) { - children[idx_pre_open_brace + 1] <- NULL + children[idx_pre_open_brace + 1L] <- NULL } has_internal_linebreak <- children %>% From 5b7f8d468ed8eafaae690897058889d79f22e1d3 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 20 Dec 2024 13:02:54 +0530 Subject: [PATCH 4/8] introduce linebreaks for only for multi-line args --- R/rules-line-breaks.R | 38 ++-- styler.Rproj | 1 + .../alignment/cols-with-one-row-out.R | 25 +-- tests/testthat/alignment/fun-decs-out.R | 12 +- tests/testthat/alignment/named-out.R | 167 ++++++------------ tests/testthat/alignment/tribble-out.R | 6 +- tests/testthat/curly-curly/mixed-out.R | 24 +-- .../indention_multiple/curly_and_round-out.R | 6 +- .../testthat/indention_multiple/overall-out.R | 15 +- .../round_closing_on_same_line-out.R | 3 +- .../eq_formals_complex_tokens-out.R | 6 +- .../not_first_trigger-out.R | 3 +- .../multi_line-no-indention-out.R | 3 +- .../multi_line-random-out.R | 6 +- .../square_brackets_double_line_break-out.R | 6 +- .../square_brackets_line_break-out.R | 20 +-- .../line_breaks_and_other/around-eq-sub-out.R | 6 +- .../base-pipe-line-breaks-out.R | 7 +- .../braces-fun-calls1-out.R | 9 +- .../line_breaks_and_other/comma-out.R | 3 +- .../line_breaks_and_other/curly-out.R | 18 +- .../if_with_line_break_indention-out.R | 9 +- .../pipe-line-breaks-out.R | 7 +- .../line_breaks_fun_call/blank-strict-out.R | 1 + .../named_arguments-out.R | 22 +-- .../switch_ifelse_etc_no_line_break-out.R | 12 +- .../token_dependent_comments-out.R | 3 +- .../token_dependent_complex_strict-out.R | 31 +--- .../token_dependent_mixed-out.R | 21 +-- .../parse_comments/with_indention-out.R | 9 +- ...ltiple-function-examples-no-last-run-out.R | 3 +- .../07-roxygen-no-dontrun-out.R | 3 +- .../08-roxygen-dontrun-out.R | 3 +- .../10-styler-r-ui-out.R | 46 ++--- .../11-start-with-dontrun-out.R | 12 +- .../scope-AsIs/scope_line_breaks-out.R | 7 +- .../scope-AsIs/scope_spaces_line_breaks-out.R | 7 +- .../scope-character/scope_line_breaks-out.R | 9 +- .../scope-character/scope_tokens-out.R | 9 +- tests/testthat/strict/strict-out.R | 25 +-- tests/testthat/unindention/mixed-double-out.R | 9 +- 41 files changed, 211 insertions(+), 421 deletions(-) diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 2e7f5e5c0..ec878a7be 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -462,29 +462,39 @@ set_line_breaks_for_multiline_args <- function(pd) { has_children <- purrr::some(pd$child, purrr::negate(is.null)) is_function_definition <- pd$token[1L] == "FUNCTION" - has_internal_linebreak <- FALSE - if (has_children && !is_function_definition) { - children <- pd$child - idx_pre_open_brace <- which(pd$token_after == "'{'") - if (length(idx_pre_open_brace)) { - children[idx_pre_open_brace + 1L] <- NULL - } + if (!has_children || is_function_definition) { + return(pd) + } - has_internal_linebreak <- children %>% - purrr::discard(is.null) %>% - purrr::map_lgl(~ sum(.x$newlines, .x$lag_newlines) > 0L) %>% - any() + children <- pd$child + + idx_pre_open_brace <- which(pd$token_after == "'{'") + if (length(idx_pre_open_brace)) { + children[idx_pre_open_brace + 1L] <- NULL } - if (!has_internal_linebreak && sum(pd$newlines, pd$lag_newlines) < 1L) { + args_multiline <- children %>% + purrr::discard(is.null) %>% + purrr::map_lgl(~ sum(.x$newlines, .x$lag_newlines) > 0L) + + if (!any(args_multiline)) { return(pd) } idx_comma <- which(pd$token == "','") idx_comma_has_comment <- which(pd$token[idx_comma + 1L] == "COMMENT") - idx_comma[idx_comma_has_comment] <- idx_comma[idx_comma_has_comment] + 1L - pd[idx_comma + 1L, "lag_newlines"] <- 1L + + for (i in seq_along(idx_comma)) { + arg_index <- i + 1L + if (arg_index <= length(args_multiline) && args_multiline[arg_index]) { + target_row <- idx_comma[i] + if (i %in% idx_comma_has_comment) 2L else 1L + if (target_row <= nrow(pd)) { + pd[target_row, "lag_newlines"] <- 1L + } + } + } pd } + diff --git a/styler.Rproj b/styler.Rproj index 30e02be1a..f4c33d288 100644 --- a/styler.Rproj +++ b/styler.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: bbbaaf9d-d7a1-475e-8d3b-3e41589b57c8 RestoreWorkspace: No SaveWorkspace: No diff --git a/tests/testthat/alignment/cols-with-one-row-out.R b/tests/testthat/alignment/cols-with-one-row-out.R index 5b2af5fc1..30893a93e 100644 --- a/tests/testthat/alignment/cols-with-one-row-out.R +++ b/tests/testthat/alignment/cols-with-one-row-out.R @@ -1,29 +1,16 @@ c( - "x", - "z", - "cgjhg", - "thi", - "z" + "x", "z", + "cgjhg", "thi", "z" ) c( - "x", - "z", - "cgjhg", - "thi", - "z" + "x", "z", + "cgjhg", "thi", "z" ) c( - "x", - "y", - "z", - "m", - "n", - "o", - "p", - "c", - "d" + "x", "y", "z", "m", "n", "o", "p", + "c", "d" ) diff --git a/tests/testthat/alignment/fun-decs-out.R b/tests/testthat/alignment/fun-decs-out.R index b64ae4e0d..fcefee559 100644 --- a/tests/testthat/alignment/fun-decs-out.R +++ b/tests/testthat/alignment/fun-decs-out.R @@ -28,15 +28,11 @@ k <- function(x = fish, # aligned k <- function(x = flus(we), - aq = x - 22, - k = 22, - ayz = m(jk5), - xfea = 3) {} + aq = x - 22, k = 22, + ayz = m(jk5), xfea = 3) {} # aligned k <- function(x = flus(we), - aq = x - 22, - k = 22, - ayz = m(jk5), - xfea = 3) {} + aq = x - 22, k = 22, + ayz = m(jk5), xfea = 3) {} diff --git a/tests/testthat/alignment/named-out.R b/tests/testthat/alignment/named-out.R index 7fe5b0ab6..35c3bb607 100644 --- a/tests/testthat/alignment/named-out.R +++ b/tests/testthat/alignment/named-out.R @@ -1,140 +1,104 @@ # algorithm: aligned. human: aligned. call( - x = 1, - kdd = 2, - xy = 2, - n = 33, + x = 1, kdd = 2, + xy = 2, n = 33, ) # without trailing comma call( - x = 1, - kdd = 2, - xy = 2, - n = 33 + x = 1, kdd = 2, + xy = 2, n = 33 ) # algorithm: aligned. human: aligned. call( - x = 1, - kdd = 2, - xy = 2, - n = 33, + x = 1, kdd = 2, + xy = 2, n = 33, ) # algorithm: aligned. human: aligned. call( - x = 1, - kdd = 2, - xy = 2, - n = 33, + x = 1, kdd = 2, + xy = 2, n = 33, ) # algorithm: not aligned (spacing around =). human: aligned (fix: spacing around =). call( - x = 1, - kdd = 2, - xy = 2, - n = 33, + x = 1, kdd = 2, + xy = 2, n = 33, ) # algorithm: not aligned. human: not aligned. call( - x = 1, - kdd = 2, - xy = 2, - n = 33, + x = 1, kdd = 2, + xy = 2, n = 33, ) # algorithm: not aligned. human: not aligned. call( - x = 1, - kdd = 2, - xy = 22, - n = 33, + x = 1, kdd = 2, + xy = 22, n = 33, ) # algorithm: not aligned. human: not aligned. call( - x = 1, - d = 2, - xy = 22, - n = 33, + x = 1, d = 2, + xy = 22, n = 33, ) # algorithm: aligned. human: aligned. call( - x = 1, - kdd = 2, - k = "abc", - xy = 2, - n = 33, - z = "333" + x = 1, kdd = 2, k = "abc", + xy = 2, n = 33, z = "333" ) # algorithm: aligned. human: aligned. call( - x = 1, - xy = 2, - n = 33, - z = "333" + x = 1, + xy = 2, n = 33, z = "333" ) # algorithm: aligned. human: aligned. call( - x = 1, - n = 33, - z = "333", + x = 1, n = 33, z = "333", xy = 2, ) # aligned. when spaces are spread accross different nests call( - k = ff("pk"), - k = 3, - b = f(-g), - 22 + 1, - 44, - 323 + k = ff("pk"), k = 3, + b = f(-g), 22 + 1, + 44, 323 ) # aligned. when spaces are spread accross different nests call( - k = ff("pk"), - k = 3, - b = f(-g), - 22 + 1, - 44, - 323, + k = ff("pk"), k = 3, + b = f(-g), 22 + 1, + 44, 323, ) # no trailing call( - k = ff("pk"), - k = 3, - b = f(-g), - 22 + 1, + k = ff("pk"), k = 3, + b = f(-g), 22 + 1, 44 ) # aligned: fewest arguments not on last line call( 44, - k = ff("pk"), - k = 3, - b = f(-g), - 22 + 1, + k = ff("pk"), k = 3, + b = f(-g), 22 + 1, ) # aligned: fewest arguments not on last line call( - k = ff("pk"), - k = 3, + k = ff("pk"), k = 3, 44, - b = f(-g), - 22 + 1, + b = f(-g), 22 + 1, ) @@ -162,47 +126,41 @@ call( # aligned (comments) call( - a = 2, - x = 111, + a = 2, x = 111, # another - bb = 3, # hi + bb = 3, # hi ) # aligned (comments) call( - a = 2, - x = 111, - bb = 3, # hi + a = 2, x = 111, + bb = 3, # hi ) # aligned (comments) call( # another one - a = 2, - x = 111, - bb = 3, # hi + a = 2, x = 111, + bb = 3, # hi ) # aligned (comments) call( # another one - a = 2, - x = 111, - bb = 3 # hi + a = 2, x = 111, + bb = 3 # hi ) # not aligned (comments) call( - a = 2, - x = 111, + a = 2, x = 111, bb = 3, # hi ) # not aligned (comments) call( # another one - a = 2, - x = 111, + a = 2, x = 111, bb = 3, # hi ) @@ -233,45 +191,30 @@ ca( # aligned =, first all named fell( - x = 8, - annoying = 3, - y = 23, # nothing in column 2 for row 2 - zz = NULL, - finally = "stuff" + x = 8, annoying = 3, + y = 23, # nothing in column 2 for row 2 + zz = NULL, finally = "stuff" ) # aligned =, first not all named gell( - p = 2, - g = gg(x), - n = 3 * 3, # - 31, - fds = -1, - gz = f / 3 + 1, + p = 2, g = gg(x), n = 3 * 3, # + 31, fds = -1, gz = f / 3 + 1, ) xgle( - 1212, - 232, - f(n = 2), - 1, - 2, - "kFlya" + 1212, 232, f(n = 2), + 1, 2, "kFlya" ) # left aligned after , call( - x = 2, - y = "another", - y = "hhjkjkbew", - x = 3 + x = 2, y = "another", + y = "hhjkjkbew", x = 3 ) call( - k = ff("pk"), - k = 3, - b = f(-g), - 22 + 1, - 44, - 323 + k = ff("pk"), k = 3, + b = f(-g), 22 + 1, + 44, 323 ) diff --git a/tests/testthat/alignment/tribble-out.R b/tests/testthat/alignment/tribble-out.R index 8a7678124..2e618487e 100644 --- a/tests/testthat/alignment/tribble-out.R +++ b/tests/testthat/alignment/tribble-out.R @@ -25,8 +25,6 @@ tribble( # has EQ_SUB which don't match, not tribble-like mlr3misc:::rowwise_table( - x = 23, - zy = 3, - y = 1, - k = 1, + x = 23, zy = 3, + y = 1, k = 1, ) diff --git a/tests/testthat/curly-curly/mixed-out.R b/tests/testthat/curly-curly/mixed-out.R index 31cbe3e00..a18134391 100644 --- a/tests/testthat/curly-curly/mixed-out.R +++ b/tests/testthat/curly-curly/mixed-out.R @@ -69,19 +69,13 @@ call( } ) -call( - "test", - { - 1 - } -) +call("test", { + 1 +}) -call( - "test", - { - 1 - } -) +call("test", { + 1 +}) call( { @@ -96,14 +90,12 @@ call( call({{ x }}, {{ y }}) call({{ x }}, {{ y }}) call( - {{ x }}, - {{ y }} + {{ x }}, {{ y }} ) call( {{ x }}, - {{ y }} := 3, - f(bk) + {{ y }} := 3, f(bk) ) call({{ diff --git a/tests/testthat/indention_multiple/curly_and_round-out.R b/tests/testthat/indention_multiple/curly_and_round-out.R index 584580b1a..f8a4acad2 100644 --- a/tests/testthat/indention_multiple/curly_and_round-out.R +++ b/tests/testthat/indention_multiple/curly_and_round-out.R @@ -5,8 +5,7 @@ test_that("this is a text", { (({ { call( - 12, - 1 + 1, + 12, 1 + 1, 26 ) } @@ -16,8 +15,7 @@ test_that("this is a text", { (({ { call( - 12, - 1 + 1, + 12, 1 + 1, 26 ) } diff --git a/tests/testthat/indention_multiple/overall-out.R b/tests/testthat/indention_multiple/overall-out.R index 860d79497..4db2b90fc 100644 --- a/tests/testthat/indention_multiple/overall-out.R +++ b/tests/testthat/indention_multiple/overall-out.R @@ -4,12 +4,9 @@ #' indented comments a <- function(x) { test_that("I want to test", { - out <- c( - 1, - c( - 22 + 1 - ) - ) + out <- c(1, c( + 22 + 1 + )) if (x > 10) { for (x in 22) { # FIXME in operator only to be surrounded by one space. What about %in%? prin(x) @@ -27,10 +24,8 @@ a <- function(x) { ) call( - 1, - 2, - 23 + Inf - 99, - call( + 1, 2, + 23 + Inf - 99, call( 16 ) ) diff --git a/tests/testthat/indention_multiple/round_closing_on_same_line-out.R b/tests/testthat/indention_multiple/round_closing_on_same_line-out.R index af183aac3..52487327d 100644 --- a/tests/testthat/indention_multiple/round_closing_on_same_line-out.R +++ b/tests/testthat/indention_multiple/round_closing_on_same_line-out.R @@ -1,5 +1,4 @@ c( - call(2), - 1, # comment + call(2), 1, # comment 29 ) diff --git a/tests/testthat/indention_operators/eq_formals_complex_tokens-out.R b/tests/testthat/indention_operators/eq_formals_complex_tokens-out.R index c6d879642..9c001e666 100644 --- a/tests/testthat/indention_operators/eq_formals_complex_tokens-out.R +++ b/tests/testthat/indention_operators/eq_formals_complex_tokens-out.R @@ -33,8 +33,6 @@ function( function(a = b, f = - d, - c = - 3, - d = + d, c = + 3, d = 4) {} diff --git a/tests/testthat/indention_operators/not_first_trigger-out.R b/tests/testthat/indention_operators/not_first_trigger-out.R index 3bb5db512..c5569c8ce 100644 --- a/tests/testthat/indention_operators/not_first_trigger-out.R +++ b/tests/testthat/indention_operators/not_first_trigger-out.R @@ -4,8 +4,7 @@ j() a <- c( - x, - y, + x, y, z ) %>% k() diff --git a/tests/testthat/indention_round_brackets/multi_line-no-indention-out.R b/tests/testthat/indention_round_brackets/multi_line-no-indention-out.R index 99ec45a29..e960a3d0d 100644 --- a/tests/testthat/indention_round_brackets/multi_line-no-indention-out.R +++ b/tests/testthat/indention_round_brackets/multi_line-no-indention-out.R @@ -1,8 +1,7 @@ call( 1, call2( - 2, - 3, + 2, 3, call3(1, 2, 22), 5 ), diff --git a/tests/testthat/indention_round_brackets/multi_line-random-out.R b/tests/testthat/indention_round_brackets/multi_line-random-out.R index 708ab28a4..98b2950bd 100644 --- a/tests/testthat/indention_round_brackets/multi_line-random-out.R +++ b/tests/testthat/indention_round_brackets/multi_line-random-out.R @@ -1,8 +1,7 @@ call( 1, call2( - 2, - 3, + 2, 3, call3(1, 2, 22), 5 ), @@ -12,8 +11,7 @@ call( call( 1, call2( - 2, - 3, + 2, 3, call3(1, 2, 22), 5 ), diff --git a/tests/testthat/indention_square_brackets/square_brackets_double_line_break-out.R b/tests/testthat/indention_square_brackets/square_brackets_double_line_break-out.R index 15edbe553..378cb936b 100644 --- a/tests/testthat/indention_square_brackets/square_brackets_double_line_break-out.R +++ b/tests/testthat/indention_square_brackets/square_brackets_double_line_break-out.R @@ -29,10 +29,8 @@ a[[ a[[ # this comment shouldn't mess - 1, - c( - 1, - 2 + 1, c( + 1, 2 # neither should this one ) diff --git a/tests/testthat/indention_square_brackets/square_brackets_line_break-out.R b/tests/testthat/indention_square_brackets/square_brackets_line_break-out.R index 505f89ca3..f888e3398 100644 --- a/tests/testthat/indention_square_brackets/square_brackets_line_break-out.R +++ b/tests/testthat/indention_square_brackets/square_brackets_line_break-out.R @@ -16,23 +16,17 @@ fac[ ] fac[ - , - `:`(a = b) + , `:`(a = b) ] fac[ - , - `:`(a = b) + , `:`(a = b) ] -fac[ - , - `:`(a = c) -] +fac[, `:`(a = c)] fac[ - , - `:`(a = c) + , `:`(a = c) ] x[a == 3 | @@ -74,10 +68,8 @@ x[ x[ # this comment shouldn't be an issue - 1, - c( - 1, - 2 + 1, c( + 1, 2 # neither should this one ) diff --git a/tests/testthat/line_breaks_and_other/around-eq-sub-out.R b/tests/testthat/line_breaks_and_other/around-eq-sub-out.R index acc545e2d..29fe9894c 100644 --- a/tests/testthat/line_breaks_and_other/around-eq-sub-out.R +++ b/tests/testthat/line_breaks_and_other/around-eq-sub-out.R @@ -28,14 +28,12 @@ c( c( - b = 4, - x # comment + b = 4, x # comment = 2 ) c( x = # comment - 2, - c = + 2, c = ) diff --git a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R index 68ecb22f8..ae22d7c9e 100644 --- a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R +++ b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R @@ -83,11 +83,8 @@ blew( ) # FIXME closing brace could go on ntext line. Alternative: move c() up. -blew( - y = 2, - x |> - c() -) +blew(y = 2, x |> + c()) { diff --git a/tests/testthat/line_breaks_and_other/braces-fun-calls1-out.R b/tests/testthat/line_breaks_and_other/braces-fun-calls1-out.R index 82f51f060..df9b2137d 100644 --- a/tests/testthat/line_breaks_and_other/braces-fun-calls1-out.R +++ b/tests/testthat/line_breaks_and_other/braces-fun-calls1-out.R @@ -3,12 +3,9 @@ test_that(x, { hh }) -test_that( - x, - { - hh - } -) +test_that(x, { + hh +}) # there are multiple brace expressions that spread over multiple lines diff --git a/tests/testthat/line_breaks_and_other/comma-out.R b/tests/testthat/line_breaks_and_other/comma-out.R index 1cde3fd9c..14842c18e 100644 --- a/tests/testthat/line_breaks_and_other/comma-out.R +++ b/tests/testthat/line_breaks_and_other/comma-out.R @@ -5,8 +5,7 @@ call( ) call( - a, - b, + a, b, c ) diff --git a/tests/testthat/line_breaks_and_other/curly-out.R b/tests/testthat/line_breaks_and_other/curly-out.R index 4a1fa2f26..22730a44b 100644 --- a/tests/testthat/line_breaks_and_other/curly-out.R +++ b/tests/testthat/line_breaks_and_other/curly-out.R @@ -5,12 +5,9 @@ if (y == 0) { 2 } -test_that( - "I am here", - { - a_test(x) - } -) +test_that("I am here", { + a_test(x) +}) # A { should always be followed by a new line @@ -30,12 +27,9 @@ if (1 > 3) { "y" } -test_that( - "I am here", - { - a_test(x) - } -) +test_that("I am here", { + a_test(x) +}) test_that( desc = "bla", diff --git a/tests/testthat/line_breaks_and_other/if_with_line_break_indention-out.R b/tests/testthat/line_breaks_and_other/if_with_line_break_indention-out.R index 46eddced9..1bd955003 100644 --- a/tests/testthat/line_breaks_and_other/if_with_line_break_indention-out.R +++ b/tests/testthat/line_breaks_and_other/if_with_line_break_indention-out.R @@ -6,9 +6,6 @@ if (x) { } # removing line-break -test_that( - "x", - { - my_test(call) - } -) +test_that("x", { + my_test(call) +}) diff --git a/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R b/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R index f86c70d11..61593b217 100644 --- a/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R +++ b/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R @@ -88,11 +88,8 @@ blew( ) # FIXME closing brace could go on ntext line. Alternative: move c() up. -blew( - y = 2, - x %>% - c() -) +blew(y = 2, x %>% + c()) { diff --git a/tests/testthat/line_breaks_fun_call/blank-strict-out.R b/tests/testthat/line_breaks_fun_call/blank-strict-out.R index fd67726ef..19232c9fa 100644 --- a/tests/testthat/line_breaks_fun_call/blank-strict-out.R +++ b/tests/testthat/line_breaks_fun_call/blank-strict-out.R @@ -20,6 +20,7 @@ call( # comment + 1, 2, 3 diff --git a/tests/testthat/line_breaks_fun_call/named_arguments-out.R b/tests/testthat/line_breaks_fun_call/named_arguments-out.R index e074a7047..485e4d609 100644 --- a/tests/testthat/line_breaks_fun_call/named_arguments-out.R +++ b/tests/testthat/line_breaks_fun_call/named_arguments-out.R @@ -1,6 +1,5 @@ call(3, - b = 2, - c + b = 2, c ) gs(3, @@ -10,25 +9,16 @@ gs(3, call(3, b = 2, c) -map(data, - fun, - x = 3, - z = 33 +map(data, fun, + x = 3, z = 33 ) map2( - dat1, - data2, - fun, - x, - y, + dat1, data2, fun, x, y, z ) -map2(dat1, - data2, - fun, - x = 1, - y = 2, +map2(dat1, data2, fun, + x = 1, y = 2, z ) diff --git a/tests/testthat/line_breaks_fun_call/switch_ifelse_etc_no_line_break-out.R b/tests/testthat/line_breaks_fun_call/switch_ifelse_etc_no_line_break-out.R index 074b50b6f..f43cd21f8 100644 --- a/tests/testthat/line_breaks_fun_call/switch_ifelse_etc_no_line_break-out.R +++ b/tests/testthat/line_breaks_fun_call/switch_ifelse_etc_no_line_break-out.R @@ -48,13 +48,11 @@ switch(x, ) if_else(a, - c, - v + c, v ) ifelse(x, - y, - z + y, z ) @@ -70,12 +68,10 @@ base::switch(f, ) dplyr::ifelse(x, - 1, - 32 + 1, 32 ) dplyr::ifelse( x, - 1, - 32 + 1, 32 ) diff --git a/tests/testthat/line_breaks_fun_call/token_dependent_comments-out.R b/tests/testthat/line_breaks_fun_call/token_dependent_comments-out.R index c3aa80b64..68cb70a94 100644 --- a/tests/testthat/line_breaks_fun_call/token_dependent_comments-out.R +++ b/tests/testthat/line_breaks_fun_call/token_dependent_comments-out.R @@ -1,6 +1,5 @@ call(call( # comment - 3, - 4 + 3, 4 )) call(call( diff --git a/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R b/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R index 72add0b92..8e0309e98 100644 --- a/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R +++ b/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R @@ -19,29 +19,19 @@ call( call(call( 1, - 2, - c( + 2, c( 3 ) )) call( 1, - call2( + call2(3, 4, call( 3, - 4, - call( - 3, - 4, - call( - 5, - 6, - call( - 2 - ) - ) - ) - ) + 4, call(5, 6, call( + 2 + )) + )) ) # comment lala @@ -50,9 +40,6 @@ call(call( 2 )) -call( - 1, - call( - 23 - ) -) +call(1, call( + 23 +)) diff --git a/tests/testthat/line_breaks_fun_call/token_dependent_mixed-out.R b/tests/testthat/line_breaks_fun_call/token_dependent_mixed-out.R index 5cfcb6160..1bd68278f 100644 --- a/tests/testthat/line_breaks_fun_call/token_dependent_mixed-out.R +++ b/tests/testthat/line_breaks_fun_call/token_dependent_mixed-out.R @@ -1,19 +1,16 @@ call(call( - call3(), - call, + call3(), call, 4433, 55 )) call(call( - call3(), - call, + call3(), call, 4433, 55 )) call(call( - call3(), - call, + call3(), call, 4433, 55 )) @@ -21,8 +18,7 @@ call(call( # no more barcket on same line -> call(call( - 3, - 4 + 3, 4 )) @@ -33,8 +29,7 @@ call( call(call( - call3(), - call, + call3(), call, 44, 55 )) @@ -42,15 +37,13 @@ call(call( # call( - call, - call(), + call, call(), 3, 4 ) call(call( - 3, - 4 + 3, 4 )) call(call( diff --git a/tests/testthat/parse_comments/with_indention-out.R b/tests/testthat/parse_comments/with_indention-out.R index c9cf55335..526802374 100644 --- a/tests/testthat/parse_comments/with_indention-out.R +++ b/tests/testthat/parse_comments/with_indention-out.R @@ -2,15 +2,12 @@ call( 1, call2( - 2, - 3, + 2, 3, call3( # zero # one # two2 - 1, - 2 # two - , - 22 # comment + 1, 2 # two + , 22 # comment ), 5 ), #' A roxygen comment diff --git a/tests/testthat/roxygen-examples-complete/06-multiple-function-examples-no-last-run-out.R b/tests/testthat/roxygen-examples-complete/06-multiple-function-examples-no-last-run-out.R index 79ca7599a..edda23f97 100644 --- a/tests/testthat/roxygen-examples-complete/06-multiple-function-examples-no-last-run-out.R +++ b/tests/testthat/roxygen-examples-complete/06-multiple-function-examples-no-last-run-out.R @@ -4,8 +4,7 @@ #' Carefully examine the results after running this function! #' @examples style_pkg( #' style = -#' tidyverse_style, -#' strict = TRUE +#' tidyverse_style, strict = TRUE #' ) #' @name k a <- 2 diff --git a/tests/testthat/roxygen-examples-complete/07-roxygen-no-dontrun-out.R b/tests/testthat/roxygen-examples-complete/07-roxygen-no-dontrun-out.R index 6ac7cee18..993d3eaa3 100644 --- a/tests/testthat/roxygen-examples-complete/07-roxygen-no-dontrun-out.R +++ b/tests/testthat/roxygen-examples-complete/07-roxygen-no-dontrun-out.R @@ -15,8 +15,7 @@ #' xfun::write_utf8("1++1", file) #' style_file( #' file, -#' style = tidyverse_style, -#' strict = TRUE +#' style = tidyverse_style, strict = TRUE #' ) #' style_file(file, transformers = tidyverse_style(strict = TRUE)) #' xfun::read_utf8(file) diff --git a/tests/testthat/roxygen-examples-complete/08-roxygen-dontrun-out.R b/tests/testthat/roxygen-examples-complete/08-roxygen-dontrun-out.R index 6fd7ffbee..8e92f97cd 100644 --- a/tests/testthat/roxygen-examples-complete/08-roxygen-dontrun-out.R +++ b/tests/testthat/roxygen-examples-complete/08-roxygen-dontrun-out.R @@ -17,8 +17,7 @@ #' } #' style_file( #' file, -#' style = tidyverse_style, -#' strict = TRUE +#' style = tidyverse_style, strict = TRUE #' ) #' style_file(file, transformers = tidyverse_style(strict = TRUE)) #' xfun::read_utf8(file) diff --git a/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R b/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R index a6e26b5d9..a7cbf3aca 100644 --- a/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R +++ b/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R @@ -73,15 +73,9 @@ style_pkg <- function(pkg = ".", exclude_files = "R/RcppExports.R", include_roxygen_examples = TRUE) { pkg_root <- rprojroot::find_package_root_file(path = pkg) - changed <- withr::with_dir( - pkg_root, - prettify_pkg( - transformers, - filetype, - exclude_files, - include_roxygen_examples - ) - ) + changed <- withr::with_dir(pkg_root, prettify_pkg( + transformers, filetype, exclude_files, include_roxygen_examples + )) invisible(changed) } @@ -94,21 +88,15 @@ prettify_pkg <- function(transformers, if ("\\.r" %in% filetype) { r_files <- dir( - path = c("R", "tests", "data-raw"), - pattern = "\\.r$", - ignore.case = TRUE, - recursive = TRUE, - full.names = TRUE + path = c("R", "tests", "data-raw"), pattern = "\\.r$", + ignore.case = TRUE, recursive = TRUE, full.names = TRUE ) } if ("\\.rmd" %in% filetype) { vignette_files <- dir( - path = "vignettes", - pattern = "\\.rmd$", - ignore.case = TRUE, - recursive = TRUE, - full.names = TRUE + path = "vignettes", pattern = "\\.rmd$", + ignore.case = TRUE, recursive = TRUE, full.names = TRUE ) readme <- dir(pattern = "^readme\\.rmd$", ignore.case = TRUE) } @@ -171,13 +159,8 @@ style_dir <- function(path = ".", exclude_files = NULL, include_roxygen_examples = TRUE) { changed <- withr::with_dir( - path, - prettify_any( - transformers, - filetype, - recursive, - exclude_files, - include_roxygen_examples + path, prettify_any( + transformers, filetype, recursive, exclude_files, include_roxygen_examples ) ) invisible(changed) @@ -196,16 +179,11 @@ prettify_any <- function(transformers, exclude_files, include_roxygen_examples) { files <- dir( - path = ".", - pattern = map_filetype_to_pattern(filetype), - ignore.case = TRUE, - recursive = recursive, - full.names = TRUE + path = ".", pattern = map_filetype_to_pattern(filetype), + ignore.case = TRUE, recursive = recursive, full.names = TRUE ) transform_files( - setdiff(files, exclude_files), - transformers, - include_roxygen_examples + setdiff(files, exclude_files), transformers, include_roxygen_examples ) } diff --git a/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R b/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R index 8624e2a08..35a804639 100644 --- a/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R +++ b/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R @@ -18,14 +18,8 @@ style_pkg <- function(pkg = ".", exclude_files = "R/RcppExports.R", include_roxygen_examples = TRUE) { pkg_root <- rprojroot::find_package_root_file(path = pkg) - changed <- withr::with_dir( - pkg_root, - prettify_pkg( - transformers, - filetype, - exclude_files, - include_roxygen_examples - ) - ) + changed <- withr::with_dir(pkg_root, prettify_pkg( + transformers, filetype, exclude_files, include_roxygen_examples + )) invisible(changed) } diff --git a/tests/testthat/scope-AsIs/scope_line_breaks-out.R b/tests/testthat/scope-AsIs/scope_line_breaks-out.R index 968e805eb..c5dd80a84 100644 --- a/tests/testthat/scope-AsIs/scope_line_breaks-out.R +++ b/tests/testthat/scope-AsIs/scope_line_breaks-out.R @@ -6,12 +6,9 @@ if (x) { } # removing line-break -test_that( -"x", - { +test_that("x", { my_test(call) - } -) + }) # do not replace assignment diff --git a/tests/testthat/scope-AsIs/scope_spaces_line_breaks-out.R b/tests/testthat/scope-AsIs/scope_spaces_line_breaks-out.R index 968e805eb..721ffc0af 100644 --- a/tests/testthat/scope-AsIs/scope_spaces_line_breaks-out.R +++ b/tests/testthat/scope-AsIs/scope_spaces_line_breaks-out.R @@ -6,12 +6,9 @@ if (x) { } # removing line-break -test_that( -"x", - { +test_that("x", { my_test(call) - } -) + }) # do not replace assignment diff --git a/tests/testthat/scope-character/scope_line_breaks-out.R b/tests/testthat/scope-character/scope_line_breaks-out.R index b4e1a8675..6a8af3216 100644 --- a/tests/testthat/scope-character/scope_line_breaks-out.R +++ b/tests/testthat/scope-character/scope_line_breaks-out.R @@ -6,12 +6,9 @@ if (x) { } # removing line-break -test_that( - "x", - { - my_test(call) - } -) +test_that("x", { + my_test(call) +}) # do not replace assignment diff --git a/tests/testthat/scope-character/scope_tokens-out.R b/tests/testthat/scope-character/scope_tokens-out.R index 11c32de5d..22b26a9cf 100644 --- a/tests/testthat/scope-character/scope_tokens-out.R +++ b/tests/testthat/scope-character/scope_tokens-out.R @@ -6,12 +6,9 @@ if (x) { } # removing line-break -test_that( - "x", - { - my_test(call) - } -) +test_that("x", { + my_test(call) +}) # do not replace assignment diff --git a/tests/testthat/strict/strict-out.R b/tests/testthat/strict/strict-out.R index 932b5239d..688cf7f88 100644 --- a/tests/testthat/strict/strict-out.R +++ b/tests/testthat/strict/strict-out.R @@ -82,12 +82,9 @@ test <- function() { # Only with conservative settings: call( - preserves, - distance, - after, - commas, - given_has, - one + preserves, distance, + after, commas, + given_has, one ) if (TRUE) { @@ -107,16 +104,14 @@ test <- function() { single_line("function", call) multiline( - "function", - call + "function", call ) nested(function_call("in", one, line)) nested(function_call( "in", - multiple, - lines + multiple, lines )) nested( @@ -128,18 +123,14 @@ test <- function() { nested( function_call(with), # a comment and many # more - , - first_level_args + , first_level_args ) difficult( nested( - "function", - call + "function", call ), - with, - more, - args + with, more, args ) } diff --git a/tests/testthat/unindention/mixed-double-out.R b/tests/testthat/unindention/mixed-double-out.R index c5c9068ef..44591e1f2 100644 --- a/tests/testthat/unindention/mixed-double-out.R +++ b/tests/testthat/unindention/mixed-double-out.R @@ -62,8 +62,7 @@ function( function( - x, - y + x, y ) { 1 } @@ -77,14 +76,12 @@ function(x, # last brace function( - x, - y) { + x, y) { NULL } function( - x, - y) { + x, y) { NULL } From 0f9cca962aba8c56c71710fc6df143d7b8e2d9dc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 20 Dec 2024 07:34:32 +0000 Subject: [PATCH 5/8] pre-commit --- R/rules-line-breaks.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index ec878a7be..9149e5e69 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -497,4 +497,3 @@ set_line_breaks_for_multiline_args <- function(pd) { pd } - From 7525889d07e34de85b610544c14c4c7112f1c7fa Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 20 Dec 2024 13:13:51 +0530 Subject: [PATCH 6/8] add another test --- .../testthat/indention_multiple/overall-in.R | 2 +- .../testthat/indention_multiple/overall-out.R | 2 +- .../base-pipe-line-breaks-in.R | 1 - .../base-pipe-line-breaks-out.R | 1 - .../pipe-line-breaks-in.R | 1 - .../pipe-line-breaks-out.R | 1 - .../line_breaks_fun_call/named_arguments-in.R | 18 +++++++++++++++ .../named_arguments-out.R | 22 +++++++++++++++++++ tests/testthat/scope-AsIs/scope_none-in.R | 2 +- tests/testthat/scope-AsIs/scope_none-out.R | 2 +- .../testthat/scope-character/scope_none-in.R | 2 +- .../testthat/scope-character/scope_none-out.R | 2 +- 12 files changed, 46 insertions(+), 10 deletions(-) diff --git a/tests/testthat/indention_multiple/overall-in.R b/tests/testthat/indention_multiple/overall-in.R index 6f9113e38..45fb3fe1a 100644 --- a/tests/testthat/indention_multiple/overall-in.R +++ b/tests/testthat/indention_multiple/overall-in.R @@ -9,7 +9,7 @@ a <- function(x) { )) if (x > 10) { for (x in 22) { # FIXME in operator only to be surrounded by one space. What about %in%? - prin(x) + print(x) } } }) diff --git a/tests/testthat/indention_multiple/overall-out.R b/tests/testthat/indention_multiple/overall-out.R index 4db2b90fc..f7dc4e2a2 100644 --- a/tests/testthat/indention_multiple/overall-out.R +++ b/tests/testthat/indention_multiple/overall-out.R @@ -9,7 +9,7 @@ a <- function(x) { )) if (x > 10) { for (x in 22) { # FIXME in operator only to be surrounded by one space. What about %in%? - prin(x) + print(x) } } }) diff --git a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-in.R b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-in.R index 641e72d52..3695fd91d 100644 --- a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-in.R +++ b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-in.R @@ -70,7 +70,6 @@ fun( s = g(x), gg = a(n == 2) |> b(), tt |> q(r = 3)) -# FIXME closing brace could go on ntext line. Alternative: remove lin breaks completely. blew(x |> c(), y = 2) diff --git a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R index ae22d7c9e..969ba47ba 100644 --- a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R +++ b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R @@ -75,7 +75,6 @@ fun( tt |> q(r = 3) ) -# FIXME closing brace could go on ntext line. Alternative: remove lin breaks completely. blew( x |> c(), diff --git a/tests/testthat/line_breaks_and_other/pipe-line-breaks-in.R b/tests/testthat/line_breaks_and_other/pipe-line-breaks-in.R index a60021669..2092a3a39 100644 --- a/tests/testthat/line_breaks_and_other/pipe-line-breaks-in.R +++ b/tests/testthat/line_breaks_and_other/pipe-line-breaks-in.R @@ -72,7 +72,6 @@ fun( s = g(x), gg = a(n == 2) %>% b, tt %>% q(r = 3)) -# FIXME closing brace could go on ntext line. Alternative: remove lin breaks completely. blew(x %>% c(), y = 2) diff --git a/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R b/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R index 61593b217..b4e021c7b 100644 --- a/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R +++ b/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R @@ -80,7 +80,6 @@ fun( tt %>% q(r = 3) ) -# FIXME closing brace could go on ntext line. Alternative: remove lin breaks completely. blew( x %>% c(), diff --git a/tests/testthat/line_breaks_fun_call/named_arguments-in.R b/tests/testthat/line_breaks_fun_call/named_arguments-in.R index f9c70a872..c0de22255 100644 --- a/tests/testthat/line_breaks_fun_call/named_arguments-in.R +++ b/tests/testthat/line_breaks_fun_call/named_arguments-in.R @@ -16,3 +16,21 @@ map2(dat1, data2, fun, x, y, map2(dat1, data2, fun, x = 1, y = 2, z ) + +c( + x, y, + c( + 'b' + ), m, n, fun(f = 2 + # comment-2 + ) +) +# comment-1 +c( + c( + 'b' + ), fun( + f = 2 + ), e, f, + g +) diff --git a/tests/testthat/line_breaks_fun_call/named_arguments-out.R b/tests/testthat/line_breaks_fun_call/named_arguments-out.R index 485e4d609..e61ff5aa8 100644 --- a/tests/testthat/line_breaks_fun_call/named_arguments-out.R +++ b/tests/testthat/line_breaks_fun_call/named_arguments-out.R @@ -22,3 +22,25 @@ map2(dat1, data2, fun, x = 1, y = 2, z ) + +c( + x, y, + c( + "b" + ), + m, n, fun( + f = 2 + # comment-2 + ) +) +# comment-1 +c( + c( + "b" + ), + fun( + f = 2 + ), + e, f, + g +) diff --git a/tests/testthat/scope-AsIs/scope_none-in.R b/tests/testthat/scope-AsIs/scope_none-in.R index 2c770501f..9948a34df 100644 --- a/tests/testthat/scope-AsIs/scope_none-in.R +++ b/tests/testthat/scope-AsIs/scope_none-in.R @@ -9,7 +9,7 @@ a<- function(x){ )) if (x > 10) { for (x in 22) { # FIXME in operator only to be surrounded by one space. What about %in%? - prin(x) + print(x) } } } ) diff --git a/tests/testthat/scope-AsIs/scope_none-out.R b/tests/testthat/scope-AsIs/scope_none-out.R index 2c770501f..9948a34df 100644 --- a/tests/testthat/scope-AsIs/scope_none-out.R +++ b/tests/testthat/scope-AsIs/scope_none-out.R @@ -9,7 +9,7 @@ a<- function(x){ )) if (x > 10) { for (x in 22) { # FIXME in operator only to be surrounded by one space. What about %in%? - prin(x) + print(x) } } } ) diff --git a/tests/testthat/scope-character/scope_none-in.R b/tests/testthat/scope-character/scope_none-in.R index 2c770501f..9948a34df 100644 --- a/tests/testthat/scope-character/scope_none-in.R +++ b/tests/testthat/scope-character/scope_none-in.R @@ -9,7 +9,7 @@ a<- function(x){ )) if (x > 10) { for (x in 22) { # FIXME in operator only to be surrounded by one space. What about %in%? - prin(x) + print(x) } } } ) diff --git a/tests/testthat/scope-character/scope_none-out.R b/tests/testthat/scope-character/scope_none-out.R index 2c770501f..9948a34df 100644 --- a/tests/testthat/scope-character/scope_none-out.R +++ b/tests/testthat/scope-character/scope_none-out.R @@ -9,7 +9,7 @@ a<- function(x){ )) if (x > 10) { for (x in 22) { # FIXME in operator only to be surrounded by one space. What about %in%? - prin(x) + print(x) } } } ) From d5f18654a8d1279038120aead23c7591b182cd1b Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 20 Dec 2024 13:37:22 +0530 Subject: [PATCH 7/8] minor --- R/rules-line-breaks.R | 3 +-- tests/testthat/test-cache-high-level-api.R | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 9149e5e69..03065167b 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -461,9 +461,8 @@ set_line_breaks_for_multiline_args <- function(pd) { } has_children <- purrr::some(pd$child, purrr::negate(is.null)) - is_function_definition <- pd$token[1L] == "FUNCTION" - if (!has_children || is_function_definition) { + if (!has_children || is_function_declaration(pd)) { return(pd) } diff --git a/tests/testthat/test-cache-high-level-api.R b/tests/testthat/test-cache-high-level-api.R index 306d41f32..e645f8bc8 100644 --- a/tests/testthat/test-cache-high-level-api.R +++ b/tests/testthat/test-cache-high-level-api.R @@ -190,8 +190,7 @@ test_that("avoid removing roxygen mask (see commit messages in #584)", { "#'", "#' @examples", "#' c(", - "#' 1,", - "#' 2,", + "#' 1, 2,", "#' x - 2", "#' )", "#' x", From c624bfcecdf31d667f5eaf144a9a2bc6a5b7add4 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 20 Dec 2024 13:54:15 +0530 Subject: [PATCH 8/8] fix another FIXME --- R/rules-line-breaks.R | 10 ++++---- .../testthat/cache-with-r-cache/mlflow-1-in.R | 3 ++- .../testthat/indention_multiple/overall-out.R | 8 ++++--- .../base-pipe-line-breaks-in.R | 1 - .../base-pipe-line-breaks-out.R | 7 +++--- .../pipe-line-breaks-in.R | 1 - .../pipe-line-breaks-out.R | 7 +++--- .../token_dependent_complex_strict-out.R | 24 ++++++++++++------- .../10-styler-r-ui-out.R | 8 ++++--- .../11-start-with-dontrun-out.R | 8 ++++--- 10 files changed, 46 insertions(+), 31 deletions(-) diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 03065167b..a123a00f2 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -461,13 +461,11 @@ set_line_breaks_for_multiline_args <- function(pd) { } has_children <- purrr::some(pd$child, purrr::negate(is.null)) - if (!has_children || is_function_declaration(pd)) { return(pd) } children <- pd$child - idx_pre_open_brace <- which(pd$token_after == "'{'") if (length(idx_pre_open_brace)) { children[idx_pre_open_brace + 1L] <- NULL @@ -475,15 +473,19 @@ set_line_breaks_for_multiline_args <- function(pd) { args_multiline <- children %>% purrr::discard(is.null) %>% - purrr::map_lgl(~ sum(.x$newlines, .x$lag_newlines) > 0L) + purrr::map_lgl(~ any(.x$is_multi_line) || sum(.x$newlines, .x$lag_newlines) > 0L) if (!any(args_multiline)) { return(pd) } + idx_paren <- which(pd$token == "'('")[1L] + if (!is.na(idx_paren) && idx_paren < nrow(pd)) { + pd[idx_paren + 1L, "lag_newlines"] <- 1L + } + idx_comma <- which(pd$token == "','") idx_comma_has_comment <- which(pd$token[idx_comma + 1L] == "COMMENT") - for (i in seq_along(idx_comma)) { arg_index <- i + 1L if (arg_index <= length(args_multiline) && args_multiline[arg_index]) { diff --git a/tests/testthat/cache-with-r-cache/mlflow-1-in.R b/tests/testthat/cache-with-r-cache/mlflow-1-in.R index eb0ebb231..556977249 100644 --- a/tests/testthat/cache-with-r-cache/mlflow-1-in.R +++ b/tests/testthat/cache-with-r-cache/mlflow-1-in.R @@ -77,7 +77,8 @@ mlflow_conda_bin <- function() { conda <- if (!is.na(conda_home)) paste(conda_home, "bin", "conda", sep = "/") else "auto" conda_try <- try(conda_binary(conda = conda), silent = TRUE) if (class(conda_try) == "try-error") { - msg <- paste(attributes(conda_try)$condition$message, + msg <- paste( + attributes(conda_try)$condition$message, paste( " If you are not using conda, you can set the environment variable", "MLFLOW_PYTHON_BIN to the path of your python executable." diff --git a/tests/testthat/indention_multiple/overall-out.R b/tests/testthat/indention_multiple/overall-out.R index f7dc4e2a2..9fb263f2f 100644 --- a/tests/testthat/indention_multiple/overall-out.R +++ b/tests/testthat/indention_multiple/overall-out.R @@ -4,9 +4,11 @@ #' indented comments a <- function(x) { test_that("I want to test", { - out <- c(1, c( - 22 + 1 - )) + out <- c( + 1, c( + 22 + 1 + ) + ) if (x > 10) { for (x in 22) { # FIXME in operator only to be surrounded by one space. What about %in%? print(x) diff --git a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-in.R b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-in.R index 3695fd91d..ac44b0602 100644 --- a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-in.R +++ b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-in.R @@ -74,7 +74,6 @@ blew(x |> c(), y = 2) -# FIXME closing brace could go on ntext line. Alternative: move c() up. blew(y = 2, x |> c()) diff --git a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R index 969ba47ba..519a6ce7c 100644 --- a/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R +++ b/tests/testthat/line_breaks_and_other/base-pipe-line-breaks-out.R @@ -81,9 +81,10 @@ blew( y = 2 ) -# FIXME closing brace could go on ntext line. Alternative: move c() up. -blew(y = 2, x |> - c()) +blew( + y = 2, x |> + c() +) { diff --git a/tests/testthat/line_breaks_and_other/pipe-line-breaks-in.R b/tests/testthat/line_breaks_and_other/pipe-line-breaks-in.R index 2092a3a39..6c584b68d 100644 --- a/tests/testthat/line_breaks_and_other/pipe-line-breaks-in.R +++ b/tests/testthat/line_breaks_and_other/pipe-line-breaks-in.R @@ -76,7 +76,6 @@ blew(x %>% c(), y = 2) -# FIXME closing brace could go on ntext line. Alternative: move c() up. blew(y = 2, x %>% c()) diff --git a/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R b/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R index b4e021c7b..beef79f5f 100644 --- a/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R +++ b/tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R @@ -86,9 +86,10 @@ blew( y = 2 ) -# FIXME closing brace could go on ntext line. Alternative: move c() up. -blew(y = 2, x %>% - c()) +blew( + y = 2, x %>% + c() +) { diff --git a/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R b/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R index 8e0309e98..0ee13430a 100644 --- a/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R +++ b/tests/testthat/line_breaks_fun_call/token_dependent_complex_strict-out.R @@ -26,12 +26,16 @@ call(call( call( 1, - call2(3, 4, call( - 3, - 4, call(5, 6, call( - 2 - )) - )) + call2( + 3, 4, call( + 3, + 4, call( + 5, 6, call( + 2 + ) + ) + ) + ) ) # comment lala @@ -40,6 +44,8 @@ call(call( 2 )) -call(1, call( - 23 -)) +call( + 1, call( + 23 + ) +) diff --git a/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R b/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R index a7cbf3aca..3a4548e2b 100644 --- a/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R +++ b/tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R @@ -73,9 +73,11 @@ style_pkg <- function(pkg = ".", exclude_files = "R/RcppExports.R", include_roxygen_examples = TRUE) { pkg_root <- rprojroot::find_package_root_file(path = pkg) - changed <- withr::with_dir(pkg_root, prettify_pkg( - transformers, filetype, exclude_files, include_roxygen_examples - )) + changed <- withr::with_dir( + pkg_root, prettify_pkg( + transformers, filetype, exclude_files, include_roxygen_examples + ) + ) invisible(changed) } diff --git a/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R b/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R index 35a804639..81c9fb987 100644 --- a/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R +++ b/tests/testthat/roxygen-examples-complete/11-start-with-dontrun-out.R @@ -18,8 +18,10 @@ style_pkg <- function(pkg = ".", exclude_files = "R/RcppExports.R", include_roxygen_examples = TRUE) { pkg_root <- rprojroot::find_package_root_file(path = pkg) - changed <- withr::with_dir(pkg_root, prettify_pkg( - transformers, filetype, exclude_files, include_roxygen_examples - )) + changed <- withr::with_dir( + pkg_root, prettify_pkg( + transformers, filetype, exclude_files, include_roxygen_examples + ) + ) invisible(changed) }