From f36e9f7ce1c598d293a2d61fe2706f81c4dcccf8 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sun, 19 Sep 2021 22:42:17 +0200 Subject: [PATCH 01/12] switch to latest pre-commit.ci --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b5da7f1a3..2800f859b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ default_stages: [commit] repos: - repo: https://github.com/lorenzwalthert/precommit - rev: v0.1.3.9014 + rev: v0.1.3.9123 hooks: - id: style-files args: [--style_pkg=styler, --style_fun=tidyverse_style] From 609e46101711786e14bdccee7c4af6ce2270a827 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sun, 19 Sep 2021 22:56:08 +0200 Subject: [PATCH 02/12] avoid pre-commit checks --- .pre-commit-config.yaml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2800f859b..62624701c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,14 +8,19 @@ repos: hooks: - id: style-files args: [--style_pkg=styler, --style_fun=tidyverse_style] - exclude: 'tests/testthat/.*/.*\.R' + exclude: > + (?x)^( + tests/testthat/.*/.*\.R| + vignettes/customizing_styler\.Rmd + )$ - id: roxygenize - id: use-tidy-description - id: spell-check exclude: > (?x)^( - data/.*| \.github/.*\.yaml| + data/.*| + tests/testthat/.*| touchstone/config\.json| (.*/|)\.Rprofile| (.*/|)\.Renviron| @@ -38,13 +43,17 @@ repos: )$ - id: readme-rmd-rendered - id: parsable-R + exclude: > + (?x)^( + tests/testthat/public-api/xyzaddin/addin_region-.*| + tests/testmanual/addins/r-invalid\.R + )$ - id: no-browser-statement - id: deps-in-desc exclude: > (?x)^( touchstone/.*| - tests/testthat/.*-in\.R(md)?| - tests/testthat/.*-out\.R(md)? + tests/testthat/.*\.R(md)? )$ - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.0.1 From d5fb483f92a7ea482f3ec0c6620741a16dd69615 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sun, 19 Sep 2021 23:09:26 +0200 Subject: [PATCH 03/12] fix pre-commit issues --- .pre-commit-config.yaml | 13 +++++++++++-- NEWS.md | 5 +++++ R/nest.R | 2 +- R/utils-cache.R | 2 +- tests/testmanual/tests | 3 +-- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 62624701c..064aa9bfb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: args: [--style_pkg=styler, --style_fun=tidyverse_style] exclude: > (?x)^( - tests/testthat/.*/.*\.R| + tests/testthat/.*/.*\.R(md)?| vignettes/customizing_styler\.Rmd )$ - id: roxygenize @@ -46,13 +46,22 @@ repos: exclude: > (?x)^( tests/testthat/public-api/xyzaddin/addin_region-.*| - tests/testmanual/addins/r-invalid\.R + tests/testmanual/addins/r-invalid\.R| + tests/testthat/escaping/basic-escape-out\.R )$ - id: no-browser-statement + exclude: > + (?x)^( + tests/testthat/public-api/xyzaddin/addin_region-.*| + tests/testmanual/addins/r-invalid\.R| + tests/testthat/escaping/basic-escape-out\.R + )$ - id: deps-in-desc exclude: > (?x)^( touchstone/.*| + tests/testmanual/addins/r-invalid\.R| + tests/testthat/escaping/basic-escape-out\.R| tests/testthat/.*\.R(md)? )$ - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/NEWS.md b/NEWS.md index b62846572..c739e37ef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# styler 1.6.1.9000 (Development version) + +* Use pre-commit.ci and improve code quality (#841). + + # styler 1.6.1 * Files with `.Rmarkdown` extension are now recognized as an R markdown files in diff --git a/R/nest.R b/R/nest.R index aa3d11c90..9fa5d96da 100644 --- a/R/nest.R +++ b/R/nest.R @@ -135,7 +135,7 @@ drop_cached_children <- function(pd) { #' @details #' Note that top-level comments **above** code have negative parents #' (the negative value of the parent of the code expression that follows after, -#' a nother comment might be in the way though), all comments that are not top +#' another comment might be in the way though), all comments that are not top #' level have positive ids. All comments for which no code follows afterwards #' have parent 0. #' @examples diff --git a/R/utils-cache.R b/R/utils-cache.R index e9e377a79..a1991d4ea 100644 --- a/R/utils-cache.R +++ b/R/utils-cache.R @@ -201,7 +201,7 @@ cache_dir_default <- function() { #' Create more specs #' -#' Syntactic suggar for creating more specs. This is useful when we want to add +#' Syntactic sugar for creating more specs. This is useful when we want to add #' more arguments (because we can search for this function in the source code). #' @keywords internal cache_more_specs <- function(include_roxygen_examples, base_indention) { diff --git a/tests/testmanual/tests b/tests/testmanual/tests index e54f0373b..118801f24 100644 --- a/tests/testmanual/tests +++ b/tests/testmanual/tests @@ -3,7 +3,7 @@ ## Addins * set style: - - test setting a valid stlye + - test setting a valid style - test setting an invalid style * style active file: - saved .R file (valid and invalid code) @@ -23,4 +23,3 @@ - unsaved .Rnw file - saved non-R file - unsaved R file - From eac4bdf8abb8c38848333fa9f5037309418240ae Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sun, 19 Sep 2021 23:33:09 +0200 Subject: [PATCH 04/12] more ignore --- .pre-commit-config.yaml | 12 +++++++++--- man/cache_more_specs.Rd | 2 +- man/find_pos_id_to_keep.Rd | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 064aa9bfb..07f8f6f6d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,8 @@ repos: exclude: > (?x)^( tests/testthat/.*/.*\.R(md)?| - vignettes/customizing_styler\.Rmd + vignettes/customizing_styler\.Rmd| + tests/testthat/public-api/xyzfile-rnw/random4\.Rnw| )$ - id: roxygenize - id: use-tidy-description @@ -47,14 +48,18 @@ repos: (?x)^( tests/testthat/public-api/xyzaddin/addin_region-.*| tests/testmanual/addins/r-invalid\.R| - tests/testthat/escaping/basic-escape-out\.R + tests/testthat/escaping/basic-escape-out\.R| + tests/testthat/indention_operators/base_pipe_and_assignment-.*| + tests/testthat/exception_handling/parser-error.R| )$ - id: no-browser-statement exclude: > (?x)^( tests/testthat/public-api/xyzaddin/addin_region-.*| tests/testmanual/addins/r-invalid\.R| - tests/testthat/escaping/basic-escape-out\.R + tests/testthat/escaping/basic-escape-out\.R| + tests/testthat/indention_operators/base_pipe_and_assignment-.*| + tests/testthat/exception_handling/parser-error.R| )$ - id: deps-in-desc exclude: > @@ -62,6 +67,7 @@ repos: touchstone/.*| tests/testmanual/addins/r-invalid\.R| tests/testthat/escaping/basic-escape-out\.R| + tests/testthat/rnw/011-conditional-eval-out\.Rnw| tests/testthat/.*\.R(md)? )$ - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/man/cache_more_specs.Rd b/man/cache_more_specs.Rd index 3cac92a92..05f78d2de 100644 --- a/man/cache_more_specs.Rd +++ b/man/cache_more_specs.Rd @@ -7,7 +7,7 @@ cache_more_specs(include_roxygen_examples, base_indention) } \description{ -Syntactic suggar for creating more specs. This is useful when we want to add +Syntactic sugar for creating more specs. This is useful when we want to add more arguments (because we can search for this function in the source code). } \keyword{internal} diff --git a/man/find_pos_id_to_keep.Rd b/man/find_pos_id_to_keep.Rd index b683b0d32..c49b4c0aa 100644 --- a/man/find_pos_id_to_keep.Rd +++ b/man/find_pos_id_to_keep.Rd @@ -22,7 +22,7 @@ typical roxygen annotated code. \details{ Note that top-level comments \strong{above} code have negative parents (the negative value of the parent of the code expression that follows after, -a nother comment might be in the way though), all comments that are not top +another comment might be in the way though), all comments that are not top level have positive ids. All comments for which no code follows afterwards have parent 0. } From ba35736d30847955ed98195126b4801cc8ed1778 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 22 Sep 2021 10:35:36 +0200 Subject: [PATCH 05/12] emergency release to comply with CRAN policy --- DESCRIPTION | 2 +- R/zzz.R | 60 ++++++++----------- ..._cache.Rd => remove_cache_old_versions.Rd} | 6 +- 3 files changed, 29 insertions(+), 39 deletions(-) rename man/{remind_removing_old_cache.Rd => remove_cache_old_versions.Rd} (81%) diff --git a/DESCRIPTION b/DESCRIPTION index 28f1fcde8..a04314cc0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: styler Title: Non-Invasive Pretty Printing of R Code -Version: 1.6.1.9000 +Version: 1.6.2 Authors@R: c(person(given = "Kirill", family = "Müller", diff --git a/R/zzz.R b/R/zzz.R index 44f47b7e5..fd793bd8a 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -13,49 +13,39 @@ ) toset <- !(names(op.styler) %in% names(op)) if (any(toset)) options(op.styler[toset]) - remind_removing_old_cache() + remove_cache_old_versions() + remove_old_cache_files() invisible() } +remove_old_cache_files <- function() { + all_cached <- list.files( + R.cache::getCachePath(c("styler", styler_version)), + full.names = TRUE + ) + date_boundary <- Sys.time() - 60 * 60 * 24 * 6 + file.remove( + all_cached[file.info(all_cached)$mtime < date_boundary] + ) +} + #' Ask people to remove the cache #' #' The way RStudio Startup works does not allow o read the prompt for some #' reasons (https://stackoverflow.com/questions/55772436/readline-does-not-prompt-user-input-from-rprofile-site-in-rstudio) #' So we better don't use the prompt and issue a message only. #' @keywords internal -remind_removing_old_cache <- function() { - if (interactive() && getOption("styler.interactive_ask_remove_old_caches", TRUE)) { - dirs <- list.dirs(R.cache::getCachePath("styler"), recursive = FALSE) - if (length(dirs) < 1) { - return() - } - dirs <- dirs[unname(sapply(dirs, function(x) length(list.files(x)) > 0))] - package_versions <- package_version(basename(dirs), strict = FALSE) - package_versions <- package_versions[!is.na(package_versions)] - old_package_versions <- package_versions[package_versions < styler_version] - if (length(old_package_versions) < 1) { - return() - } - - cmd <- glue::glue("styler::cache_clear(\"{basename(dirs)}\", ask = FALSE)") %>% - paste0(collapse = "\n") - cli::cli_alert_info(paste0( - "You are using {{styler}} version {styler_version} but we found ", - "caches for older versions of {{styler}}.\n", - "You can delete them with the following commands:" - )) - cat("\n") - cli::cli_code(cmd) - cat("\n") - cli::cli_alert_info( - paste( - "We'll remind you every time you update {{styler}}.", - "To suppress this prompt in the future:" - ) - ) - cat("\n") - cli::cli_code( - 'options("styler.interactive_ask_remove_old_caches" = FALSE)' - ) +remove_cache_old_versions <- function() { + dirs <- list.dirs(R.cache::getCachePath("styler"), recursive = FALSE) + if (length(dirs) < 1) { + return() + } + old_package_dirs <- dirs[basename(dirs) != as.character(styler_version)] + if (length(old_package_dirs) < 1) { + return() } + purrr::walk(old_package_dirs, function(dir) { + cache_clear(basename(dir), ask = FALSE) + file.remove(dir) + }) } diff --git a/man/remind_removing_old_cache.Rd b/man/remove_cache_old_versions.Rd similarity index 81% rename from man/remind_removing_old_cache.Rd rename to man/remove_cache_old_versions.Rd index cc40e1847..2917fffcc 100644 --- a/man/remind_removing_old_cache.Rd +++ b/man/remove_cache_old_versions.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/zzz.R -\name{remind_removing_old_cache} -\alias{remind_removing_old_cache} +\name{remove_cache_old_versions} +\alias{remove_cache_old_versions} \title{Ask people to remove the cache} \usage{ -remind_removing_old_cache() +remove_cache_old_versions() } \description{ The way RStudio Startup works does not allow o read the prompt for some From 6c7d2d3bbcff91a9287d464f6806b2eacda3d5cc Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 22 Sep 2021 13:11:09 +0200 Subject: [PATCH 06/12] drop unused option --- .pre-commit-config.yaml | 2 +- R/zzz.R | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 07f8f6f6d..115c448f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ default_stages: [commit] repos: - repo: https://github.com/lorenzwalthert/precommit - rev: v0.1.3.9123 + rev: v0.1.3.9014 hooks: - id: style-files args: [--style_pkg=styler, --style_fun=tidyverse_style] diff --git a/R/zzz.R b/R/zzz.R index fd793bd8a..8675e3bd6 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -8,8 +8,7 @@ styler.ignore_start = "# styler: off", styler.ignore_stop = "# styler: on", styler.quiet = FALSE, - styler.test_dir_writable = TRUE, - styler.interactive_ask_remove_old_caches = TRUE + styler.test_dir_writable = TRUE ) toset <- !(names(op.styler) %in% names(op)) if (any(toset)) options(op.styler[toset]) From 51b5ac0c65ca8a300835379aff8c58f8611d0f3b Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 22 Sep 2021 21:41:02 +0200 Subject: [PATCH 07/12] delete outdated documentation --- R/zzz.R | 7 +------ man/remove_cache_old_versions.Rd | 14 -------------- 2 files changed, 1 insertion(+), 20 deletions(-) delete mode 100644 man/remove_cache_old_versions.Rd diff --git a/R/zzz.R b/R/zzz.R index 8675e3bd6..5cee6b37c 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -28,12 +28,7 @@ remove_old_cache_files <- function() { ) } -#' Ask people to remove the cache -#' -#' The way RStudio Startup works does not allow o read the prompt for some -#' reasons (https://stackoverflow.com/questions/55772436/readline-does-not-prompt-user-input-from-rprofile-site-in-rstudio) -#' So we better don't use the prompt and issue a message only. -#' @keywords internal + remove_cache_old_versions <- function() { dirs <- list.dirs(R.cache::getCachePath("styler"), recursive = FALSE) if (length(dirs) < 1) { diff --git a/man/remove_cache_old_versions.Rd b/man/remove_cache_old_versions.Rd deleted file mode 100644 index 2917fffcc..000000000 --- a/man/remove_cache_old_versions.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/zzz.R -\name{remove_cache_old_versions} -\alias{remove_cache_old_versions} -\title{Ask people to remove the cache} -\usage{ -remove_cache_old_versions() -} -\description{ -The way RStudio Startup works does not allow o read the prompt for some -reasons (https://stackoverflow.com/questions/55772436/readline-does-not-prompt-user-input-from-rprofile-site-in-rstudio) -So we better don't use the prompt and issue a message only. -} -\keyword{internal} From 580031bf58c3dff408db9000a1dd7da65a902868 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Wed, 22 Sep 2021 21:49:35 +0200 Subject: [PATCH 08/12] file.remove does not work on Windows for directories. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kirill Müller --- R/zzz.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 5cee6b37c..54dfbe4d7 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -39,7 +39,6 @@ remove_cache_old_versions <- function() { return() } purrr::walk(old_package_dirs, function(dir) { - cache_clear(basename(dir), ask = FALSE) - file.remove(dir) + unlink(dir, recursive = TRUE, force = TRUE) }) } From ca6485910bd6e5bf0bc7546a146a639dff1690aa Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Wed, 22 Sep 2021 21:52:57 +0200 Subject: [PATCH 09/12] should not make a difference but not worse... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kirill Müller --- R/zzz.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index 54dfbe4d7..9a3a62522 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -20,7 +20,7 @@ remove_old_cache_files <- function() { all_cached <- list.files( R.cache::getCachePath(c("styler", styler_version)), - full.names = TRUE + full.names = TRUE, recursive = TRUE ) date_boundary <- Sys.time() - 60 * 60 * 24 * 6 file.remove( From 9028950893715f7ccaaf9468a3aa8c293c90bc59 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 22 Sep 2021 21:57:53 +0200 Subject: [PATCH 10/12] drop unnecessary conditions --- R/zzz.R | 6 ------ 1 file changed, 6 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 9a3a62522..2917d4f6f 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -31,13 +31,7 @@ remove_old_cache_files <- function() { remove_cache_old_versions <- function() { dirs <- list.dirs(R.cache::getCachePath("styler"), recursive = FALSE) - if (length(dirs) < 1) { - return() - } old_package_dirs <- dirs[basename(dirs) != as.character(styler_version)] - if (length(old_package_dirs) < 1) { - return() - } purrr::walk(old_package_dirs, function(dir) { unlink(dir, recursive = TRUE, force = TRUE) }) From f54a039bbf2e85a68c58f1c22b0608d50e4fa1a5 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 22 Sep 2021 22:00:30 +0200 Subject: [PATCH 11/12] update NEWS --- NEWS.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index c739e37ef..586b55446 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,6 @@ -# styler 1.6.1.9000 (Development version) - -* Use pre-commit.ci and improve code quality (#841). +# styler 1.2 +* clean up cache files older than one week (#842). # styler 1.6.1 From 76a1e09fc891e1635c5380273b65a508fcf7220b Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 22 Sep 2021 22:03:42 +0200 Subject: [PATCH 12/12] update cran comments --- cran-comments.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cran-comments.md b/cran-comments.md index 7a71a7c37..63c531556 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,6 +1,8 @@ -This is a submission to fix a problem with persistent caching, reported by -Prof Ripley on 07.09.2021, and invalid URLs, based on an email from Uwe Ligges -on 17.09.2021. +This is a re-submission to fix a problem with persistent caching. Note that +all cached files are of size 0 and this is by design to keep the cache small. +Hence, the cache will still have files of size 0, but we remove all files older +than a week and remove all caches for versions of styler other than the one +running as requested. ## Test environments