Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce line-breaks in multiline arguments #1244

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
fix another FIXME
IndrajeetPatil committed Dec 20, 2024

Verified

This commit was signed with the committer’s verified signature.
hakimifr Hakimi
commit c624bfcecdf31d667f5eaf144a9a2bc6a5b7add4
10 changes: 6 additions & 4 deletions R/rules-line-breaks.R
Original file line number Diff line number Diff line change
@@ -461,29 +461,31 @@ 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
}

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]) {
3 changes: 2 additions & 1 deletion tests/testthat/cache-with-r-cache/mlflow-1-in.R
Original file line number Diff line number Diff line change
@@ -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."
8 changes: 5 additions & 3 deletions tests/testthat/indention_multiple/overall-out.R
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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())

Original file line number Diff line number Diff line change
@@ -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()
)


{
1 change: 0 additions & 1 deletion tests/testthat/line_breaks_and_other/pipe-line-breaks-in.R
Original file line number Diff line number Diff line change
@@ -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())

7 changes: 4 additions & 3 deletions tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R
Original file line number Diff line number Diff line change
@@ -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()
)


{
Original file line number Diff line number Diff line change
@@ -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
)
)
8 changes: 5 additions & 3 deletions tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R
Original file line number Diff line number Diff line change
@@ -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)
}

Original file line number Diff line number Diff line change
@@ -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)
}