From 975fefd236d62b5aab8a2f89e5d36ff5af77e457 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Fri, 2 Jun 2023 16:18:02 -0400 Subject: [PATCH 1/3] Use cli messaging for cache --- R/zzz.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 6d17357ba..3f7fe061a 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -64,9 +64,9 @@ ask_to_switch_to_non_default_cache_root <- function(ask = interactive()) { ask_to_switch_to_non_default_cache_root_impl <- function() { - rlang::inform(paste0( + cli::cli_inform(paste0( "{styler} cache is cleared after 6 days. ", - "See `?styler::caching` to configure differently or silence this message." + "See {.help styler::caching} to configure differently or silence this message." )) } From d8209128efcf45515b0efb128b1c45b0bb0ffe53 Mon Sep 17 00:00:00 2001 From: Olivier Roy Date: Sat, 3 Jun 2023 16:36:20 -0400 Subject: [PATCH 2/3] Improve other warning or error messages * Fix with autolinking in vignette * Update a test that I broke. --- R/set-assert-args.R | 10 +++++----- R/stylerignore.R | 4 ++-- R/vertical.R | 4 ++-- R/zzz.R | 2 +- tests/testthat/test-public_api-3.R | 2 +- vignettes/remove_rules.Rmd | 5 ++--- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/R/set-assert-args.R b/R/set-assert-args.R index 7d2a0c21c..db49c4097 100644 --- a/R/set-assert-args.R +++ b/R/set-assert-args.R @@ -28,22 +28,22 @@ assert_transformers <- function(transformers) { action <- if (utils::packageVersion("styler") >= version_cutoff) { "are not supported anymore" } else { - "depreciated and will be removed in a future version of styler." + "deprecated and will be removed in a future version of styler." } message <- paste( "Style guides without a name and a version field are", action, "\nIf you are a user: Open an issue on", "https://github.com/r-lib/styler and provide a reproducible example", "of this error. \nIf you are a developer:", - "When you create a style guide with `styler::create_style_guide()`, the", + "When you create a style guide with {.fn styler::create_style_guide}, the", "argument `style_guide_name` and `style_guide_version` should be", - "non-NULL. See help(\"create_style_guide\") for how to set them." + "non-NULL. See {.help styler::create_style_guide} for how to set them." ) if (utils::packageVersion("styler") >= version_cutoff) { - rlang::abort(message) + cli::cli_abort(message) } else { - rlang::warn(message) + cli::cli_warn(message) } } } diff --git a/R/stylerignore.R b/R/stylerignore.R index ce558dfd6..4cf0b30bd 100644 --- a/R/stylerignore.R +++ b/R/stylerignore.R @@ -76,9 +76,9 @@ add_stylerignore <- function(pd_flat) { pd_flat$indicator_off <- cumsum_start + cumsum_stop is_invalid <- cumsum_start - cumsum_stop < 0L | cumsum_start - cumsum_stop > 1L if (any(is_invalid)) { - warn(paste0( + cli::cli_warn(paste0( "Invalid stylerignore sequences found, potentially ignoring some of the ", - "markers set.\nSee `help(\"stylerignore\", \"styler\")`." + "markers set.\nSee {.help styler::stylerignore}." )) } diff --git a/R/vertical.R b/R/vertical.R index 3f04c7286..8062185a1 100644 --- a/R/vertical.R +++ b/R/vertical.R @@ -24,10 +24,10 @@ print.vertical <- function(x, ..., if (is_installed("prettycode")) { x <- prettycode::highlight(x, style = style) } else { - warn(paste( + cli::cli_warn(paste( "Could not use `colored = TRUE`, as the package prettycode is not", "installed. Please install it if you want to see colored output", - "or see `?print.vertical` for more information." + "or see {.help styler::print.vertical} for more information." )) } } diff --git a/R/zzz.R b/R/zzz.R index 3f7fe061a..bee69d85d 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -65,7 +65,7 @@ ask_to_switch_to_non_default_cache_root <- function(ask = interactive()) { ask_to_switch_to_non_default_cache_root_impl <- function() { cli::cli_inform(paste0( - "{styler} cache is cleared after 6 days. ", + "{{styler}} cache is cleared after 6 days. ", "See {.help styler::caching} to configure differently or silence this message." )) } diff --git a/tests/testthat/test-public_api-3.R b/tests/testthat/test-public_api-3.R index 35757d559..8b1e926fb 100644 --- a/tests/testthat/test-public_api-3.R +++ b/tests/testthat/test-public_api-3.R @@ -153,7 +153,7 @@ test_that("Can display warning on unset styler cache", { withr::local_seed(7) expect_message( ask_to_switch_to_non_default_cache_root(ask = TRUE), - "See `?styler::caching`", + regexp = "styler::caching", fixed = TRUE ) }) diff --git a/vignettes/remove_rules.Rmd b/vignettes/remove_rules.Rmd index 11c79ae63..c0f076239 100644 --- a/vignettes/remove_rules.Rmd +++ b/vignettes/remove_rules.Rmd @@ -25,8 +25,7 @@ If you want to change the behavior of styler to match your desired style, there are multiple ways: - Use the tidyverse style guide, but not with the default options. Starting - point for this approach is the [help - file](https://styler.r-lib.org/reference/tidyverse_style.html) for the + point for this approach is the `help("tidyverse_style")` for the function `tidyverse_style()`, which returns the transformer functions that prettify your code. Most of these options are explained in `vignette("styler")`. @@ -164,7 +163,7 @@ styler. - Then pinpoint the probable rule type (e.g. line breaks if you want less new lines). -- In a local styler clone, add e.g. a `return(pd` at the top of the body to +- In a local styler clone, add e.g. a `return(pd)` at the top of the body to deactivate the rule quickly, or add a `print(pd)` or `browser()` call in the functions of that type (e.g. the different functions of `R/rules-line-breaks.R`), `load_all()`, run your example, see if that From 015874f1dc0c5cbd08bfa2077d74c10223022f27 Mon Sep 17 00:00:00 2001 From: Olivier Roy Date: Sat, 3 Jun 2023 16:42:39 -0400 Subject: [PATCH 3/3] Fix failing test. --- tests/testthat/test-exception_handling.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-exception_handling.R b/tests/testthat/test-exception_handling.R index 11e1cbb71..74afef5e8 100644 --- a/tests/testthat/test-exception_handling.R +++ b/tests/testthat/test-exception_handling.R @@ -32,6 +32,6 @@ test_that("warning is given when transformers does not contain a version", { } expect_fun( assert_transformers(sg), - "name and a version field are depreciated and will be removed in a future version of styler" + "name and a version field are deprecated and will be removed in a future version of styler" ) })