Skip to content

Commit

Permalink
fix another FIXME
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Dec 20, 2024
1 parent d5f1865 commit c624bfc
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 31 deletions.
10 changes: 6 additions & 4 deletions R/rules-line-breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
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
Expand Up @@ -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."
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/indention_multiple/overall-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())

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


{
Expand Down
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
Expand Up @@ -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())

Expand Down
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
Expand Up @@ -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()
)


{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Up @@ -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)
}

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

0 comments on commit c624bfc

Please sign in to comment.