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 }