Skip to content

Commit 5df9c8a

Browse files
Merge branch 'main' into issue-931
2 parents 7219ef4 + eec45e4 commit 5df9c8a

12 files changed

+113
-7
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: styler
33
Title: Non-Invasive Pretty Printing of R Code
4-
Version: 1.7.0.9000
4+
Version: 1.7.0.9001
55
Authors@R:
66
c(person(given = "Kirill",
77
family = "Müller",

NEWS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
# styler 1.7.0.9000 (Development version)
22

3+
**Features**
4+
35
* `filetype` `.qmd` is now supported, but not turned on by default (#931).
6+
* new R option `styler.ignore_alignment` controls if alignment should be
7+
detected (and preserved) or not (#932).
8+
9+
**Bug Fixes**
410

11+
* the cache is also invalidated on changing the stylerignore markers (#932).
512

613

714
# styler 1.7.0
815

16+
* if `else` follows directly after `if`, line breaks are removed (#935).
17+
918
**API changes**
1019

1120
* new R option `styler.cache_root` (defaulting to `"styler"`) that determines

R/rules-line-breaks.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ style_line_break_around_curly <- function(strict, pd) {
153153
pd$lag_newlines[is_else] <- 0L
154154
pd$spaces[c(is_else, FALSE)[-1]] <- 1L
155155
}
156+
is_if_after_else <- pd$token == "ELSE" & pd$token_after == "IF"
157+
pd$lag_newlines[lag(is_if_after_else)] <- 0L
156158
}
157159
pd
158160
}

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/utils-cache.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,13 @@ get_cache_dir <- function(cache_name = cache_get_name()) {
204204
#' Syntactic sugar for creating more specs. This is useful when we want to add
205205
#' more arguments (because we can search for this function in the source code).
206206
#' @keywords internal
207-
cache_more_specs <- function(include_roxygen_examples, base_indention) {
207+
cache_more_specs <- function(include_roxygen_examples,
208+
base_indention) {
208209
list(
209210
include_roxygen_examples = include_roxygen_examples,
210-
base_indention = base_indention
211+
base_indention = base_indention,
212+
ignore_alignment = getOption("styler.ignore_alignment", FALSE),
213+
ignore_start = getOption("styler.ignore_start", .default_ignore_start),
214+
ignore_stop = getOption("styler.ignore_start", .default_ignore_stop)
211215
)
212216
}

R/zzz.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
.default_ignore_start <- "styler: off"
2+
.default_ignore_stop <- "styler: on"
3+
14
.onLoad <- function(libname, pkgname) {
25
op <- options()
36
op.styler <- list(
47
styler.addins_style_transformer = "styler::tidyverse_style()",
58
styler.cache_root = NULL,
69
styler.cache_name = styler_version,
710
styler.colored_print.vertical = TRUE,
8-
styler.ignore_start = "styler: off",
9-
styler.ignore_stop = "styler: on",
11+
styler.ignore_alignment = FALSE,
12+
styler.ignore_start = .default_ignore_start,
13+
styler.ignore_stop = .default_ignore_stop,
1014
styler.quiet = FALSE,
1115
styler.test_dir_writable = TRUE
1216
)

inst/hooks/require-news-update.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/local/bin/Rscript
22
args <- system2(
33
"git",
4-
c("diff", "upstream/main", "--name-only"),
4+
c("diff", "origin/main", "--name-only"),
55
stdout = TRUE
66
)
77

tests/testthat/indention_multiple/if_else_curly-in.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,18 @@ foo <- function(x) {
3737
2
3838
}
3939
}
40+
41+
42+
if (TRUE) {
43+
3
44+
} else
45+
if (FALSE) {
46+
4
47+
}
48+
49+
if (TRUE) {
50+
3
51+
} else # comment
52+
if (FALSE) {
53+
4
54+
}

tests/testthat/indention_multiple/if_else_curly-out.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,17 @@ foo <- function(x) {
3636
2
3737
}
3838
}
39+
40+
41+
if (TRUE) {
42+
3
43+
} else if (FALSE) {
44+
4
45+
}
46+
47+
if (TRUE) {
48+
3
49+
} else # comment
50+
if (FALSE) {
51+
4
52+
}

tests/testthat/test-cache-interaction-more-specs.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ test_that("base_indention is respected in caching", {
1010
)
1111
})
1212

13+
test_that("ignore_alignment is respected in caching", {
14+
local_test_setup(cache = TRUE)
15+
text <- c("call(", " arxone = 1,", " tw3 = 2", ")")
16+
text_without_alignment <- c("call(", " arxone = 1,", " tw3 = 2", ")")
17+
with_detection <- style_text(text)
18+
withr::local_options(styler.ignore_alignment = TRUE)
19+
without_detection <- style_text(text)
20+
expect_equal(
21+
as.character(without_detection),
22+
as.character(text_without_alignment)
23+
)
24+
expect_equal(cache_info(format = "tabular")$n, 2)
25+
})
26+
1327
test_that("cache is deactivated at end of caching related testthat file", {
1428
expect_false(cache_is_activated())
1529
})

0 commit comments

Comments
 (0)