Skip to content

Commit a2cfaf5

Browse files
also add stylerignore markers to more_specs
1 parent 1460d81 commit a2cfaf5

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
* New R option `styler.ignore_alignment` controls if alignment should be
1+
* new R option `styler.ignore_alignment` controls if alignment should be
22
detected (and preserved) or not (#932).
3+
* the cache is also invalidated on changing the stylerignore markers (#932).
34

45
# styler 1.7.0
56

R/utils-cache.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ cache_more_specs <- function(include_roxygen_examples,
209209
list(
210210
include_roxygen_examples = include_roxygen_examples,
211211
base_indention = base_indention,
212-
ignore_alignment = getOption("styler.ignore_alignment", FALSE)
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)
213215
)
214216
}

R/zzz.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
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(
@@ -6,8 +9,8 @@
69
styler.cache_name = styler_version,
710
styler.colored_print.vertical = TRUE,
811
styler.ignore_alignment = FALSE,
9-
styler.ignore_start = "styler: off",
10-
styler.ignore_stop = "styler: on",
12+
styler.ignore_start = .default_ignore_start,
13+
styler.ignore_stop = .default_ignore_stop,
1114
styler.quiet = FALSE,
1215
styler.test_dir_writable = TRUE
1316
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test_that("ignore_alignment is respected in caching", {
2121
as.character(without_detection),
2222
as.character(text_without_alignment)
2323
)
24-
cache_info(format = "tabular")$size == 2
24+
expect_equal(cache_info(format = "tabular")$n, 2)
2525
})
2626

2727
test_that("cache is deactivated at end of caching related testthat file", {

tests/testthat/test-interaction-caching-stylerignore.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,25 @@ test_that("indention preserved in stylerignore when caching activated", {
168168
)
169169
})
170170

171+
test_that("changing ignore markers invalidates cache", {
172+
opts <- list(
173+
list(styler.ignore_stop = "noqua: stop", n = 1),
174+
list(styler.ignore_start = "noqua: start", n = 3)
175+
)
176+
purrr::walk(opts, function(opt) {
177+
local_test_setup(cache = TRUE)
178+
text7 <- c(
179+
"# styler: off",
180+
"1 + 1",
181+
"# styler: on"
182+
)
183+
style_text(text7)
184+
rlang::exec(withr::local_options, !!!opt[-length(opt)])
185+
style_text(text7)
186+
expect_equal(cache_info(format = "tabular")$n, opt[["n"]])
187+
})
188+
})
189+
171190
test_that("cache is deactivated at end of caching related testthat file", {
172191
expect_false(cache_is_activated())
173192
})

0 commit comments

Comments
 (0)