diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4bb1af251..a45eaf64f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ default_language_version: repos: - repo: https://github.com/lorenzwalthert/precommit - rev: v0.3.2.9007 + rev: f3498c421d68a1db26de1a1fe3ecc91dd6f03b5e hooks: - id: style-files args: diff --git a/DESCRIPTION b/DESCRIPTION index 94ecae74c..434ff833e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: styler Title: Non-Invasive Pretty Printing of R Code -Version: 1.10.0.9000 +Version: 1.10.1 Authors@R: c(person(given = "Kirill", family = "Müller", diff --git a/NEWS.md b/NEWS.md index 9efbd2658..6dc69a941 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,12 @@ - +# styler 1.10.1 + +This release was requested by CRAN due to accidentally populating a user cache while building vignettes for R >= 4.3.0. + +* Code quality improvements (#1122). +* Bump JamesIves/github-pages-deploy-action from 4.4.1 to 4.4.2 (#1123). + +Thanks to everyone who contributed to this release: [@olivroy](https://github.com/olivroy) and [@krlmlr](https://github.com/krlmlr). + # styler 1.10.0 This release contains speed-ups between 20% and 40% depending on your use case diff --git a/R/zzz.R b/R/zzz.R index bee69d85d..77b90ee17 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -76,7 +76,7 @@ remove_old_cache_files <- function() { path_version_specific, full.names = TRUE, recursive = TRUE ) - date_boundary <- Sys.time() - 60L * 60L * 24L * 6L + date_boundary <- Sys.time() - as.difftime(6L, units = "days") file.remove( all_cached[file.info(all_cached)$mtime < date_boundary] ) diff --git a/cran-comments.md b/cran-comments.md index 229978c38..ed38adf29 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -4,8 +4,8 @@ editor_options: wrap: 79 --- -This is a release requested by the CRAN team to delete empty directories in the -user's cache. +This is a release requested by the CRAN team to delete the population of the +user's cache while building vignettes. ## Test environments diff --git a/inst/WORDLIST b/inst/WORDLIST index b6a53ac74..1e14ad162 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -107,6 +107,7 @@ iNZightTools io ixmypi ized +JamesIves Jupyterlab Kirill kirill diff --git a/tests/testthat/test-cache-clean-up.R b/tests/testthat/test-cache-clean-up.R new file mode 100644 index 000000000..66adce823 --- /dev/null +++ b/tests/testthat/test-cache-clean-up.R @@ -0,0 +1,23 @@ +test_that("styler tests did not use R.cache in user root", { + skip_on_cran() + skip_on_covr() + skip_during_parallel() + expect_true( + length(list.files(R.cache::getCachePath("styler"), recursive = TRUE)) == 0L + ) +}) + +test_that("clear Cache", { + # if R CMD CHECK is detected, R.cache root is set to a temp + # directory by default. + # https://github.com/HenrikBengtsson/R.cache/commit/c7ac171f15f035674346d5504049c38cf07c268f + # Hence, this clean up won't clean up the user directory. + skip_during_parallel() + cache_path <- R.cache::getCachePath("styler") + R.cache::clearCache(cache_path, recursive = TRUE, prompt = FALSE) + skip_on_cran() + skip_on_covr() + expect_true( + length(list.dirs(R.cache::getCachePath("styler"))) == 1L + ) +}) diff --git a/tests/testthat/test-zzz.R b/tests/testthat/test-zzz.R index f9d01d9f1..dbbee5082 100644 --- a/tests/testthat/test-zzz.R +++ b/tests/testthat/test-zzz.R @@ -1,21 +1,3 @@ -test_that("styler tests did not use R.cache in user root", { - skip_on_cran() - skip_on_covr() - expect_true( - length(list.files(R.cache::getCachePath("styler"), recursive = TRUE)) == 0L - ) -}) - -test_that("clear Cache", { - R.cache::clearCache(R.cache::getCachePath("styler"), recursive = TRUE) - skip_on_cran() - skip_on_covr() - expect_true( - length(list.dirs(R.cache::getCachePath("styler"))) == 1L - ) -}) - - test_that("can delete empty cache directory", { skip_if(getRversion() < package_version("4.0.0")) skip_on_cran() diff --git a/vignettes/caching.Rmd b/vignettes/caching.Rmd index b5f9a7553..b15c7b92a 100644 --- a/vignettes/caching.Rmd +++ b/vignettes/caching.Rmd @@ -12,6 +12,8 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) +options(styler.colored_print.vertical = FALSE) +styler::cache_deactivate() ``` ```{r setup} diff --git a/vignettes/customizing_styler.Rmd b/vignettes/customizing_styler.Rmd index 5a681c435..e566daabd 100644 --- a/vignettes/customizing_styler.Rmd +++ b/vignettes/customizing_styler.Rmd @@ -7,6 +7,15 @@ vignette: > %\VignetteEncoding{UTF-8} --- +```{r} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +options(styler.colored_print.vertical = FALSE) +styler::cache_deactivate() +``` + This vignette provides a high-level overview of how styler works and how you can define your own style guide and format code according to it. If you simply want to customize the tidyverse style guide to your needs, check out `vignette("styler")`, to remove some rules, have a look at `vignette("remove_rules")`. How to distribute a custom style guide is described in `vignette("distribute_custom_style_guides")`. # How styler works diff --git a/vignettes/detect-alignment.Rmd b/vignettes/detect-alignment.Rmd index 937d2921e..b3872d7f5 100644 --- a/vignettes/detect-alignment.Rmd +++ b/vignettes/detect-alignment.Rmd @@ -8,7 +8,12 @@ vignette: > --- ```{r, include=FALSE} -knitr::opts_chunk$set(eval = FALSE) +knitr::opts_chunk$set( + eval = FALSE, + collapse = TRUE, + comment = "#>" +) +styler::cache_deactivate() ``` # Overview diff --git a/vignettes/distribute_custom_style_guides.Rmd b/vignettes/distribute_custom_style_guides.Rmd index 0284facc8..031a13876 100644 --- a/vignettes/distribute_custom_style_guides.Rmd +++ b/vignettes/distribute_custom_style_guides.Rmd @@ -12,6 +12,8 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) +styler::cache_deactivate() +options(styler.colored_print.vertical = FALSE) ``` This vignette describes how you can distribute your own style guide. It builds on `vignette("customizing_styler")` and assumes you understand how to create a style guide with `create_style_guide()`. diff --git a/vignettes/remove_rules.Rmd b/vignettes/remove_rules.Rmd index c0f076239..657538c76 100644 --- a/vignettes/remove_rules.Rmd +++ b/vignettes/remove_rules.Rmd @@ -15,6 +15,7 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) +styler::cache_deactivate() ``` ```{r, echo = FALSE, include = FALSE} @@ -60,7 +61,9 @@ Here are the steps required to deactivate a rule you don't like Lets assume you want to remove the rule that turns `=` into `<-` for assignment. That means you want - string = "hi there" +``` +string = "hi there" +``` to remain unchanged after applying styler. This is not the case if you use the default style guide of styler: diff --git a/vignettes/strict.Rmd b/vignettes/strict.Rmd index f73d98679..880a5db10 100644 --- a/vignettes/strict.Rmd +++ b/vignettes/strict.Rmd @@ -14,6 +14,8 @@ knitr::opts_chunk$set( results = "hide" ) +styler::cache_deactivate() + knitr::knit_engines$set(list( styler = function(options) { options$comment <- "" diff --git a/vignettes/styler.Rmd b/vignettes/styler.Rmd index 2428465fa..dcb451adc 100644 --- a/vignettes/styler.Rmd +++ b/vignettes/styler.Rmd @@ -21,6 +21,7 @@ knitr::knit_engines$set(list( )) options(styler.colored_print.vertical = FALSE) +styler::cache_deactivate() ``` # Entry-points @@ -35,14 +36,18 @@ styler provides the following API to format code: - RStudio Addins for styling the active file, styling the current package and styling the highlighted selection, see `help("styler_addins")`. -Beyond that, styler can be used through other tools documented in the `vignette("third-party-integrations")`. +Beyond that, styler can be used through other tools documented in the `vignette("third-party-integrations")`. Let's get started. +```{r} +library(styler) +``` + + ### Passing arguments to the style guide styler separates the abstract definition of a style guide from the application of it. That's why you must supply a style guide via `transformers` when styling (in case you don't want to rely on the defaults): ```{r} -library(styler) style_text("a + b", transformers = tidyverse_style(scope = "indention")) ```