Skip to content

Commit 06a3696

Browse files
new R option to ignore alignment
1 parent 28d92df commit 06a3696

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* New R option `styler.ignore_alignment` controls if alignment should be
2+
detected (and preserved) or not (#932).
3+
14
# styler 1.7.0
25

36
* if `else` follows directly after `if`, line breaks are removed (#935).

R/rules-spaces.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ set_space_around_op <- function(pd_flat, strict) {
1818
}
1919
if (sum(pd_flat$lag_newlines) > 2 &&
2020
is_function_call(pd_flat) &&
21-
any(pd_flat$token %in% c("EQ_SUB", "','"))
21+
any(pd_flat$token %in% c("EQ_SUB", "','")) &&
22+
!getOption("styler.ignore_alignment", FALSE)
2223
) {
2324
is_on_aligned_line <- token_is_on_aligned_line(pd_flat)
2425
} else {

R/zzz.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
styler.cache_root = NULL,
66
styler.cache_name = styler_version,
77
styler.colored_print.vertical = TRUE,
8+
styler.ignore_alignment = FALSE,
89
styler.ignore_start = "styler: off",
910
styler.ignore_stop = "styler: on",
1011
styler.quiet = FALSE,

tests/testthat/test-public_api.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,27 @@ test_that("Can display warning on unset styler cache", {
496496
withr::local_seed(7)
497497
expect_silent(ask_to_switch_to_non_default_cache_root(ask = TRUE))
498498
})
499+
500+
501+
test_that("alignment detection can be turned off.", {
502+
withr::local_options(
503+
"styler.ignore_alignment" = TRUE,
504+
"styler.colored_print.vertical" = FALSE
505+
)
506+
text_in <- paste0(
507+
"call(\n",
508+
" xb = 13,\n",
509+
" t = 'a'\n",
510+
")"
511+
)
512+
text_out <- c(
513+
"call(",
514+
" xb = 13,",
515+
" t = \"a\"",
516+
")"
517+
)
518+
519+
expect_true(all(
520+
style_text(text_in) == text_out
521+
))
522+
})

0 commit comments

Comments
 (0)