From c624bfcecdf31d667f5eaf144a9a2bc6a5b7add4 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 20 Dec 2024 13:54:15 +0530 Subject: [PATCH] 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) }