Skip to content

Commit 014d73d

Browse files
Merge pull request #894 from lorenzwalthert/issue-893
fix and test .onLoad()
2 parents f672907 + 6a29ecf commit 014d73d

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525

2626
**Other changes**
2727

28+
* `.onLoad()` method no longer broken with {cli} >= 3.1 (#893).
2829
* Piped function without brackets `substitute(x %>% y)` don't get `()` added
29-
anymore, as this can change outcome of the code (#876).
30+
anymore for one level deep (not more yet, see #889), as this can change
31+
outcome of the code (#876).
3032
* rules that add tokens don't break stylerignore sequences anymore (#891).
3133
* Add vignette on distributing style guide (#846, #861).
3234
* Alignment detection respects stylerignore (#850).

R/zzz.R

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,29 @@
2121

2222
ask_to_switch_to_non_default_cache_root <- function(ask = interactive()) {
2323
if (ask && runif(1) > 0.9 && is.null(getOption("styler.cache_root"))) {
24-
cli::cli_inform(paste0(
25-
"The R option `styler.cache_root` is not set, which means the cache ",
26-
"will get cleaned up after 6 days (and repeated styling will be slower).",
27-
" To keep cache files longer, set ",
28-
"the option to location within the {{R.cache}} cache where you want to ",
29-
"store the cache, e.g. `\"styler-perm\"`.\n\n",
30-
"options(styler.cache_root = \"styler-perm\")\n\n",
31-
"in your .Rprofile. Note that the cache literally ",
32-
"takes zero space on your disk, only the inode, and you can always ",
33-
"manually clean up with `styler::cache_clear()`, and if you update the ",
34-
"{{styler}} package, the cache is removed in any case. To ignore this ",
35-
"message in the future, set the default explictly to \"styler\" with\n\n",
36-
"options(styler.cache_root = \"styler\")\n\nin your `.Rprofile`. This ",
37-
"message will only be displayed once in a while.\n"
38-
))
24+
ask_to_switch_to_non_default_cache_root_impl()
3925
options(styler.cache_root = "styler")
4026
}
4127
}
4228

29+
ask_to_switch_to_non_default_cache_root_impl <- function() {
30+
rlang::warn(paste0(
31+
"The R option `styler.cache_root` is not set, which means the cache ",
32+
"will get cleaned up after 6 days (and repeated styling will be slower).",
33+
" To keep cache files longer, set ",
34+
"the option to location within the {R.cache} cache where you want to ",
35+
"store the cache, e.g. `\"styler-perm\"`.\n\n",
36+
"options(styler.cache_root = \"styler-perm\")\n\n",
37+
"in your .Rprofile. Note that the cache literally ",
38+
"takes zero space on your disk, only the inode, and you can always ",
39+
"manually clean up with `styler::cache_clear()`, and if you update the ",
40+
"{styler} package, the cache is removed in any case. To ignore this ",
41+
"message in the future, set the default explictly to \"styler\" with\n\n",
42+
"options(styler.cache_root = \"styler\")\n\nin your `.Rprofile`. This ",
43+
"message will only be displayed once in a while.\n"
44+
))
45+
}
46+
4347
remove_old_cache_files <- function() {
4448
all_cached <- list.files(
4549
R.cache::getCachePath(c("styler", styler_version)),

tests/testthat/test-public_api.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,19 @@ test_that("Can properly determine style_after_saving", {
475475
expect_equal(op, FALSE)
476476
})
477477
})
478+
479+
test_that("Can display warning on unset styler cache", {
480+
withr::local_options(styler.cache_root = NULL)
481+
withr::local_seed(7)
482+
expect_warning(
483+
ask_to_switch_to_non_default_cache_root(ask = TRUE),
484+
'options(styler.cache_root = "styler-perm")',
485+
fixed = TRUE
486+
)
487+
})
488+
489+
test_that("Can display warning on unset styler cache", {
490+
withr::local_options(styler.cache_root = "styler-perm")
491+
withr::local_seed(7)
492+
expect_silent(ask_to_switch_to_non_default_cache_root(ask = TRUE))
493+
})

0 commit comments

Comments
 (0)