From cc9b380c7dabbf207d2ad74c9b3e0a6275dad936 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 12:29:08 +0200 Subject: [PATCH 001/114] fix version in NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 586b55446..9d7d6eacb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# styler 1.2 +# styler 1.6.2 * clean up cache files older than one week (#842). From 88595fca5d4de68fb830b4082088d679d94233c1 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 12:33:16 +0200 Subject: [PATCH 002/114] make this the devel version --- DESCRIPTION | 2 +- NEWS.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index a04314cc0..f9db73dbf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: styler Title: Non-Invasive Pretty Printing of R Code -Version: 1.6.2 +Version: 1.6.2.9000 Authors@R: c(person(given = "Kirill", family = "Müller", diff --git a/NEWS.md b/NEWS.md index 9d7d6eacb..dc6b65b2d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# styler 1.6.2.9000 (Development version) + + # styler 1.6.2 * clean up cache files older than one week (#842). From 1ec967f6bd42af88736f1c468ecfb6a0530c0fb2 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 10:44:32 +0200 Subject: [PATCH 003/114] eof --- .gitattributes | 2 +- tests/testthat/indention_multiple/edge_strict_random-in.R | 1 - tests/testthat/indention_operators/plus_minus-in.R | 1 - .../testthat/indention_round_brackets/arithmetic_no_start-in.R | 1 - .../if_else_if_else_non_strict-in.R | 1 - .../insertion_comment_interaction/if_else_if_else_strict-in.R | 1 - .../testthat/insertion_comment_interaction/just_if_strict-in.R | 2 +- .../6-multiple-function-examples-no-last-run-in.R | 1 - .../6-multiple-function-examples-not-last-proper-run.R | 1 - tests/testthat/serialize_tests/correct-in.R | 1 - tests/testthat/serialize_tests/correct-out.R | 1 - tests/testthat/stylerignore/simple-in.R | 1 - tests/testthat/token_adding_removing/add_brackets_in_pipe-in.R | 1 - vignettes/caching.Rmd | 1 - 14 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.gitattributes b/.gitattributes index f2e9ea02a..0f2dadb50 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -tests/testthat/**/*_tree linguist-generated=true \ No newline at end of file +tests/testthat/**/*_tree linguist-generated=true diff --git a/tests/testthat/indention_multiple/edge_strict_random-in.R b/tests/testthat/indention_multiple/edge_strict_random-in.R index cc8f8c0c5..7ec47f29d 100644 --- a/tests/testthat/indention_multiple/edge_strict_random-in.R +++ b/tests/testthat/indention_multiple/edge_strict_random-in.R @@ -11,4 +11,3 @@ { c("x", "y", "z", "sin(x)") } - diff --git a/tests/testthat/indention_operators/plus_minus-in.R b/tests/testthat/indention_operators/plus_minus-in.R index a543addce..079b0918f 100644 --- a/tests/testthat/indention_operators/plus_minus-in.R +++ b/tests/testthat/indention_operators/plus_minus-in.R @@ -5,4 +5,3 @@ 5 1 + 1 - diff --git a/tests/testthat/indention_round_brackets/arithmetic_no_start-in.R b/tests/testthat/indention_round_brackets/arithmetic_no_start-in.R index e4d2a565a..01e7fb8e3 100644 --- a/tests/testthat/indention_round_brackets/arithmetic_no_start-in.R +++ b/tests/testthat/indention_round_brackets/arithmetic_no_start-in.R @@ -1,4 +1,3 @@ 1 + 2 + ( 3 + 4) - diff --git a/tests/testthat/insertion_comment_interaction/if_else_if_else_non_strict-in.R b/tests/testthat/insertion_comment_interaction/if_else_if_else_non_strict-in.R index 7296968b6..7699633d2 100644 --- a/tests/testthat/insertion_comment_interaction/if_else_if_else_non_strict-in.R +++ b/tests/testthat/insertion_comment_interaction/if_else_if_else_non_strict-in.R @@ -38,4 +38,3 @@ TRUE)NULL else if(FALSE)NULL else NULL if # comment (TRUE)NULL else if(FALSE)NULL else NULL - diff --git a/tests/testthat/insertion_comment_interaction/if_else_if_else_strict-in.R b/tests/testthat/insertion_comment_interaction/if_else_if_else_strict-in.R index 7296968b6..7699633d2 100644 --- a/tests/testthat/insertion_comment_interaction/if_else_if_else_strict-in.R +++ b/tests/testthat/insertion_comment_interaction/if_else_if_else_strict-in.R @@ -38,4 +38,3 @@ TRUE)NULL else if(FALSE)NULL else NULL if # comment (TRUE)NULL else if(FALSE)NULL else NULL - diff --git a/tests/testthat/insertion_comment_interaction/just_if_strict-in.R b/tests/testthat/insertion_comment_interaction/just_if_strict-in.R index 643a9de03..5fbaf5d47 100644 --- a/tests/testthat/insertion_comment_interaction/just_if_strict-in.R +++ b/tests/testthat/insertion_comment_interaction/just_if_strict-in.R @@ -13,4 +13,4 @@ if( # comment TRUE)NULL if # comment -(TRUE)NULL \ No newline at end of file +(TRUE)NULL diff --git a/tests/testthat/roxygen-examples-complete/6-multiple-function-examples-no-last-run-in.R b/tests/testthat/roxygen-examples-complete/6-multiple-function-examples-no-last-run-in.R index 8ae3f8614..9b8c45923 100644 --- a/tests/testthat/roxygen-examples-complete/6-multiple-function-examples-no-last-run-in.R +++ b/tests/testthat/roxygen-examples-complete/6-multiple-function-examples-no-last-run-in.R @@ -20,4 +20,3 @@ a <- 2 #' @importFrom purrr partial #' @export a <- call; - diff --git a/tests/testthat/roxygen-examples-identify/6-multiple-function-examples-not-last-proper-run.R b/tests/testthat/roxygen-examples-identify/6-multiple-function-examples-not-last-proper-run.R index 2156d22ad..1ecfe7bcf 100644 --- a/tests/testthat/roxygen-examples-identify/6-multiple-function-examples-not-last-proper-run.R +++ b/tests/testthat/roxygen-examples-identify/6-multiple-function-examples-not-last-proper-run.R @@ -18,4 +18,3 @@ a <- 2 #' @importFrom purrr partial #' @export a <- call - diff --git a/tests/testthat/serialize_tests/correct-in.R b/tests/testthat/serialize_tests/correct-in.R index d70f6df36..01e79c32a 100644 --- a/tests/testthat/serialize_tests/correct-in.R +++ b/tests/testthat/serialize_tests/correct-in.R @@ -1,4 +1,3 @@ 1 2 3 - diff --git a/tests/testthat/serialize_tests/correct-out.R b/tests/testthat/serialize_tests/correct-out.R index d70f6df36..01e79c32a 100644 --- a/tests/testthat/serialize_tests/correct-out.R +++ b/tests/testthat/serialize_tests/correct-out.R @@ -1,4 +1,3 @@ 1 2 3 - diff --git a/tests/testthat/stylerignore/simple-in.R b/tests/testthat/stylerignore/simple-in.R index da04e6081..f507d8cea 100644 --- a/tests/testthat/stylerignore/simple-in.R +++ b/tests/testthat/stylerignore/simple-in.R @@ -23,4 +23,3 @@ more_calls(with(arguments)) # styler: off 1 + 1 a(!b) - diff --git a/tests/testthat/token_adding_removing/add_brackets_in_pipe-in.R b/tests/testthat/token_adding_removing/add_brackets_in_pipe-in.R index 6bc56624d..a803abadb 100644 --- a/tests/testthat/token_adding_removing/add_brackets_in_pipe-in.R +++ b/tests/testthat/token_adding_removing/add_brackets_in_pipe-in.R @@ -3,4 +3,3 @@ 1 %x% y 1 %>% x 1 %s% 1 - diff --git a/vignettes/caching.Rmd b/vignettes/caching.Rmd index 64048bd89..1dc68fcbe 100644 --- a/vignettes/caching.Rmd +++ b/vignettes/caching.Rmd @@ -107,4 +107,3 @@ changes introduced here: For more detailed explanation and documentation, please consult the help files of the internals. - From e493577228112dc575c4224e32218615d635bb32 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 11:52:35 +0200 Subject: [PATCH 004/114] various fixes --- .pre-commit-config.yaml | 10 ++++++++-- R/rules-line-breaks.R | 3 ++- man/set_line_break_before_curly_opening.Rd | 3 ++- tests/testthat/public-api/xyzpackage-rmd/NAMESPACE | 1 - tests/testthat/public-api/xyzpackage-rnw/NAMESPACE | 1 - tests/testthat/test-public_api.R | 2 +- vignettes/caching.Rmd | 4 ++-- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 115c448f8..e25165a08 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(md)?| + tests/testthat/.*/.*\.R(md|nw)?| vignettes/customizing_styler\.Rmd| tests/testthat/public-api/xyzfile-rnw/random4\.Rnw| )$ @@ -76,7 +76,13 @@ repos: - id: check-added-large-files args: ['--maxkb=200'] - id: end-of-file-fixer - exclude: '\.Rd' + exclude: > + (?x)^( + \.Rd| + tests/testthat/exception_handling/empty_file\.R| + tests/testthat/parse_comments/eol_eof_spaces-.*| + tests/testthat/reference-objects/.*| + )$ - repo: local hooks: - id: forbid-to-commit diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index eb93240e4..3212ee46f 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -41,7 +41,8 @@ #' # brace expressions go on new line if part of a pipe, in function call... #' c( #' data %>% -#' filter(bar) %>% { +#' filter(bar) %>% +#' { #' cor(.$col1, .$col2, use = "complete.obs") #' } #' ) diff --git a/man/set_line_break_before_curly_opening.Rd b/man/set_line_break_before_curly_opening.Rd index bae84e953..f2f2efd9a 100644 --- a/man/set_line_break_before_curly_opening.Rd +++ b/man/set_line_break_before_curly_opening.Rd @@ -50,7 +50,8 @@ tryGugus( # brace expressions go on new line if part of a pipe, in function call... c( data \%>\% - filter(bar) \%>\% { + filter(bar) \%>\% + { cor(.$col1, .$col2, use = "complete.obs") } ) diff --git a/tests/testthat/public-api/xyzpackage-rmd/NAMESPACE b/tests/testthat/public-api/xyzpackage-rmd/NAMESPACE index 6ae926839..e651b9448 100644 --- a/tests/testthat/public-api/xyzpackage-rmd/NAMESPACE +++ b/tests/testthat/public-api/xyzpackage-rmd/NAMESPACE @@ -1,2 +1 @@ # Generated by roxygen2: do not edit by hand - diff --git a/tests/testthat/public-api/xyzpackage-rnw/NAMESPACE b/tests/testthat/public-api/xyzpackage-rnw/NAMESPACE index 6ae926839..e651b9448 100644 --- a/tests/testthat/public-api/xyzpackage-rnw/NAMESPACE +++ b/tests/testthat/public-api/xyzpackage-rnw/NAMESPACE @@ -1,2 +1 @@ # Generated by roxygen2: do not edit by hand - diff --git a/tests/testthat/test-public_api.R b/tests/testthat/test-public_api.R index 177e975cf..5226db1cb 100644 --- a/tests/testthat/test-public_api.R +++ b/tests/testthat/test-public_api.R @@ -395,7 +395,7 @@ test_that("dry run options work:", { test_dry(test_path("public-api/dry/unstyled.Rmd"), style_file, styled = FALSE) test_dry(test_path("public-api/dry/styled.Rmd"), style_file, styled = TRUE) - ## Rmd + ## Rnw test_dry(test_path("public-api/dry/unstyled.Rnw"), style_file, styled = FALSE) test_dry(test_path("public-api/dry/styled.Rnw"), style_file, styled = TRUE) }) diff --git a/vignettes/caching.Rmd b/vignettes/caching.Rmd index 1dc68fcbe..fa47d18fb 100644 --- a/vignettes/caching.Rmd +++ b/vignettes/caching.Rmd @@ -44,8 +44,8 @@ The main caching features were implemented in the following two pull requests: ```{r, eval = FALSE} function() { - # a comment - x = 2 # <- change this line + # a comment + x <- 2 # <- change this line } another(call) From 0da05e677d20ad18c6a62829734246228323a282 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 11:52:58 +0200 Subject: [PATCH 005/114] use latest {precommit} version --- .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 e25165a08..e5fce9efd 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.9124 hooks: - id: style-files args: [--style_pkg=styler, --style_fun=tidyverse_style] From bdda2318551673aa50e86a577a0c53ee481eb6f3 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 11:56:07 +0200 Subject: [PATCH 006/114] ignore alignment vignette --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e5fce9efd..b2ac1f38f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,6 +13,7 @@ repos: tests/testthat/.*/.*\.R(md|nw)?| vignettes/customizing_styler\.Rmd| tests/testthat/public-api/xyzfile-rnw/random4\.Rnw| + vignettes/detect-alignment\.Rmd| )$ - id: roxygenize - id: use-tidy-description From e28903e4f3fa1bc9c076b0e39309108e22507812 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 11:57:49 +0200 Subject: [PATCH 007/114] styler --- DESCRIPTION | 2 +- R/rules-line-breaks.R | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f9db73dbf..5e1cd3751 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,7 +46,7 @@ VignetteBuilder: Encoding: UTF-8 Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "collate", "pkgapi::api_roclet")) -RoxygenNote: 7.1.1.9001 +RoxygenNote: 7.1.2 Collate: 'addins.R' 'communicate.R' diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 3212ee46f..eb93240e4 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -41,8 +41,7 @@ #' # brace expressions go on new line if part of a pipe, in function call... #' c( #' data %>% -#' filter(bar) %>% -#' { +#' filter(bar) %>% { #' cor(.$col1, .$col2, use = "complete.obs") #' } #' ) From f0b8f939d5a16ae5bcf67cad16a3a82c5115adf4 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 12:03:55 +0200 Subject: [PATCH 008/114] no invalid files --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b2ac1f38f..c80d3257e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,6 +14,7 @@ repos: vignettes/customizing_styler\.Rmd| tests/testthat/public-api/xyzfile-rnw/random4\.Rnw| vignettes/detect-alignment\.Rmd| + tests/testmanual/addins/.*invalid.*| )$ - id: roxygenize - id: use-tidy-description From d98a97cffb811a4b7f9ae74d9a23f0a36a2e7a3f Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 12:14:32 +0200 Subject: [PATCH 009/114] purl can't work when header has outside dependencies (https://github.com/yihui/knitr/issues/1938) --- tests/testthat/rnw/011-conditional-eval-in.Rnw | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/rnw/011-conditional-eval-in.Rnw b/tests/testthat/rnw/011-conditional-eval-in.Rnw index 14b53e0ba..e33cd957e 100644 --- a/tests/testthat/rnw/011-conditional-eval-in.Rnw +++ b/tests/testthat/rnw/011-conditional-eval-in.Rnw @@ -7,11 +7,11 @@ dothis <- TRUE @ -<>= +<>= print( "say hello world" ) @ -<>= +<>= print( "silence is gold" ) @ From 019b8660a4271335d54d24307ffce85c94d97b3f Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 12:17:52 +0200 Subject: [PATCH 010/114] more exclusion --- .pre-commit-config.yaml | 2 +- tests/testthat/public-api/xyzfile-rnw/random4.Rnw | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c80d3257e..196b6b3c0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -67,7 +67,7 @@ repos: exclude: > (?x)^( touchstone/.*| - tests/testmanual/addins/r-invalid\.R| + tests/testmanual/addins/.*invalid.*| tests/testthat/escaping/basic-escape-out\.R| tests/testthat/rnw/011-conditional-eval-out\.Rnw| tests/testthat/.*\.R(md)? diff --git a/tests/testthat/public-api/xyzfile-rnw/random4.Rnw b/tests/testthat/public-api/xyzfile-rnw/random4.Rnw index 4b929ff4c..691bda529 100644 --- a/tests/testthat/public-api/xyzfile-rnw/random4.Rnw +++ b/tests/testthat/public-api/xyzfile-rnw/random4.Rnw @@ -11,7 +11,7 @@ f <- function(x) { @ More text -<<>>= +<>= # More R code which is invalid g <- function(y) { y From d541d265d4f6959a51efb6cc85eb2d51c60a006c Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 12:20:26 +0200 Subject: [PATCH 011/114] more exclusion --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 196b6b3c0..7a3dcfd0d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,6 +15,7 @@ repos: tests/testthat/public-api/xyzfile-rnw/random4\.Rnw| vignettes/detect-alignment\.Rmd| tests/testmanual/addins/.*invalid.*| + tests/testmanual/addins/r-valid\.R| )$ - id: roxygenize - id: use-tidy-description From d5614e51e59d813f9cff88b7de5f070535511cfc Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 12:24:07 +0200 Subject: [PATCH 012/114] re-roxygenize --- .pre-commit-config.yaml | 2 ++ R/addins.R | 4 ++-- man/combine_children.Rd | 4 ++-- man/set_line_break_before_curly_opening.Rd | 3 +-- man/styler_addins.Rd | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7a3dcfd0d..afb87edfe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,6 +18,8 @@ repos: tests/testmanual/addins/r-valid\.R| )$ - id: roxygenize + additional_dependencies: + - r-lib/pkgapi - id: use-tidy-description - id: spell-check exclude: > diff --git a/R/addins.R b/R/addins.R index 44f7c3fea..5e265b11f 100644 --- a/R/addins.R +++ b/R/addins.R @@ -3,8 +3,8 @@ #' Helper functions for styling via RStudio Addins. #' @section Addins: #' - Set style: Select the style transformers to use. For flexibility, the user -#' input is passed to the `transformers` argument, not the `style` argument, so -#' entering `styler::tidyverse_style(scope = "spaces")` in the Addin is +#' input is passed to the `transformers` argument, not the `style` argument, +#' so entering `styler::tidyverse_style(scope = "spaces")` in the Addin is #' equivalent to `styler::style_text("1+1", scope = "spaces")` and #' `styler::style_text("1+1", transformers = styler::tidyverse_style(scope = "spaces"))` #' if the text to style is `1+1`. The style transformers are memorized diff --git a/man/combine_children.Rd b/man/combine_children.Rd index fef5d4a3a..f587b9aaf 100644 --- a/man/combine_children.Rd +++ b/man/combine_children.Rd @@ -16,8 +16,8 @@ Binds two parse tables together and arranges them so that the tokens are in the correct order. } \details{ -Essentially, this is a wrapper around \code{\link[dplyr:bind]{dplyr::bind_rows()}}, but -returns \code{NULL} if the result of \code{\link[dplyr:bind]{dplyr::bind_rows()}} is a data frame with +Essentially, this is a wrapper around \code{\link[dplyr:bind_rows]{dplyr::bind_rows()}}, but +returns \code{NULL} if the result of \code{\link[dplyr:bind_rows]{dplyr::bind_rows()}} is a data frame with zero rows. } \keyword{internal} diff --git a/man/set_line_break_before_curly_opening.Rd b/man/set_line_break_before_curly_opening.Rd index f2f2efd9a..bae84e953 100644 --- a/man/set_line_break_before_curly_opening.Rd +++ b/man/set_line_break_before_curly_opening.Rd @@ -50,8 +50,7 @@ tryGugus( # brace expressions go on new line if part of a pipe, in function call... c( data \%>\% - filter(bar) \%>\% - { + filter(bar) \%>\% { cor(.$col1, .$col2, use = "complete.obs") } ) diff --git a/man/styler_addins.Rd b/man/styler_addins.Rd index 052b6ffa6..24daeb37f 100644 --- a/man/styler_addins.Rd +++ b/man/styler_addins.Rd @@ -10,8 +10,8 @@ Helper functions for styling via RStudio Addins. \itemize{ \item Set style: Select the style transformers to use. For flexibility, the user -input is passed to the \code{transformers} argument, not the \code{style} argument, so -entering \code{styler::tidyverse_style(scope = "spaces")} in the Addin is +input is passed to the \code{transformers} argument, not the \code{style} argument, +so entering \code{styler::tidyverse_style(scope = "spaces")} in the Addin is equivalent to \code{styler::style_text("1+1", scope = "spaces")} and \code{styler::style_text("1+1", transformers = styler::tidyverse_style(scope = "spaces"))} if the text to style is \code{1+1}. The style transformers are memorized From bfcc429e8fc31d6d7129c7b2508e31fecef65136 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 10:40:55 +0200 Subject: [PATCH 013/114] styler --- R/communicate.R | 2 +- vignettes/detect-alignment.Rmd | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/R/communicate.R b/R/communicate.R index bb1a87a57..e4e0b58dd 100644 --- a/R/communicate.R +++ b/R/communicate.R @@ -7,7 +7,7 @@ #' @inheritParams can_verify_roundtrip #' @keywords internal communicate_warning <- function(changed, transformers) { - if (any(changed, na.rm = TRUE) && + if (any(changed, na.rm = TRUE) && !can_verify_roundtrip(transformers) && !getOption("styler.quiet", FALSE) ) { diff --git a/vignettes/detect-alignment.Rmd b/vignettes/detect-alignment.Rmd index a8c8b2b12..d2b5dfd84 100644 --- a/vignettes/detect-alignment.Rmd +++ b/vignettes/detect-alignment.Rmd @@ -60,7 +60,7 @@ tibble::tribble( "long string", "shrt" # columns can overlap ('~' above ',') ) -# right-aligned after = +# right-aligned after = purrr::map(x, fun, # arguments on same line as opening brace are not considered arg2 = 2, ar = f(k, x) @@ -122,7 +122,6 @@ gell( p = 2, g = gg(x), n = 3 * 3, # 31, fds = -1, gz = f / 3, ) - ``` ... or match position of `=` vertically and align everything after this operator From 19384bd4b4732803f307869e3c61bf06d82ec26a Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 12:33:50 +0200 Subject: [PATCH 014/114] add news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index dc6b65b2d..67ddf22cc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # styler 1.6.2.9000 (Development version) +* Enable pre-commit.ci (#843) # styler 1.6.2 From dbe6d7f9d5f9be83408db03d05f4bb43368683cc Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 13:04:13 +0200 Subject: [PATCH 015/114] exclude more --- .pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index afb87edfe..56508a593 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -54,7 +54,7 @@ repos: tests/testthat/public-api/xyzaddin/addin_region-.*| tests/testmanual/addins/r-invalid\.R| tests/testthat/escaping/basic-escape-out\.R| - tests/testthat/indention_operators/base_pipe_and_assignment-.*| + tests/testthat/indention_operators/.*pipe.*| tests/testthat/exception_handling/parser-error.R| )$ - id: no-browser-statement @@ -65,6 +65,7 @@ repos: tests/testthat/escaping/basic-escape-out\.R| tests/testthat/indention_operators/base_pipe_and_assignment-.*| tests/testthat/exception_handling/parser-error.R| + tests/testthat/indention_operators/.*pipe.*| )$ - id: deps-in-desc exclude: > From 4c1d0b651f13304e57a6d79b341f4a84dff93375 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 13:14:10 +0200 Subject: [PATCH 016/114] bump version --- .pre-commit-config.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 56508a593..594fa75e3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -55,6 +55,7 @@ repos: tests/testmanual/addins/r-invalid\.R| tests/testthat/escaping/basic-escape-out\.R| tests/testthat/indention_operators/.*pipe.*| + tests/testthat/line_breaks_and_other/.*pipe.*| tests/testthat/exception_handling/parser-error.R| )$ - id: no-browser-statement @@ -63,9 +64,9 @@ repos: tests/testthat/public-api/xyzaddin/addin_region-.*| tests/testmanual/addins/r-invalid\.R| tests/testthat/escaping/basic-escape-out\.R| - tests/testthat/indention_operators/base_pipe_and_assignment-.*| - tests/testthat/exception_handling/parser-error.R| tests/testthat/indention_operators/.*pipe.*| + tests/testthat/line_breaks_and_other/.*pipe.*| + tests/testthat/exception_handling/parser-error.R| )$ - id: deps-in-desc exclude: > From e575a7e8046fa9c59e731fa80ffddefbab5cb640 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 17:48:35 +0200 Subject: [PATCH 017/114] autoupdate --- .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 594fa75e3..df1e19a01 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.9124 + rev: v0.1.3.9125 hooks: - id: style-files args: [--style_pkg=styler, --style_fun=tidyverse_style] From 3cd7dfc73609403a1e5bc2af0c3ab31f95d2a1b5 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 18:32:06 +0200 Subject: [PATCH 018/114] try newever pre-commit version --- .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 df1e19a01..4aa3bdfd2 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.9125 + rev: v0.1.3.9126 hooks: - id: style-files args: [--style_pkg=styler, --style_fun=tidyverse_style] From b919c6f8eb2a7e8a738abf204ee0a1d36e750eeb Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 18:49:09 +0200 Subject: [PATCH 019/114] also fix out file --- tests/testthat/rnw/011-conditional-eval-out.Rnw | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/rnw/011-conditional-eval-out.Rnw b/tests/testthat/rnw/011-conditional-eval-out.Rnw index 48f3a9348..67c6d81a1 100644 --- a/tests/testthat/rnw/011-conditional-eval-out.Rnw +++ b/tests/testthat/rnw/011-conditional-eval-out.Rnw @@ -7,11 +7,11 @@ dothis <- TRUE @ -<>= +<>= print("say hello world") @ -<>= +<>= print("silence is gold") @ From d41e35303071562c82a7b9934f352261510e59e4 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 19:06:58 +0200 Subject: [PATCH 020/114] use latest hooks --- .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 4aa3bdfd2..2735cfe77 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.9126 + rev: v0.1.3.9127 hooks: - id: style-files args: [--style_pkg=styler, --style_fun=tidyverse_style] From 44dcbc2651461c41697fec2a0ee1edaff9df3e40 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Fri, 1 Oct 2021 23:39:47 +0200 Subject: [PATCH 021/114] add vignette --- NEWS.md | 1 + R/utils-cache.R | 2 +- _pkgdown.yml | 1 + inst/WORDLIST | 2 + man/cache_by_expression.Rd | 4 ++ man/cache_make_key.Rd | 2 +- man/cache_write.Rd | 4 ++ vignettes/customizing_styler.Rmd | 3 +- vignettes/distribute_custom_style_guide.Rmd | 73 +++++++++++++++++++++ 9 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 vignettes/distribute_custom_style_guide.Rmd diff --git a/NEWS.md b/NEWS.md index dc6b65b2d..89516bfe3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # styler 1.6.2.9000 (Development version) +* Add vignette on distributing style guide (#846). # styler 1.6.2 diff --git a/R/utils-cache.R b/R/utils-cache.R index a1991d4ea..e31a5f233 100644 --- a/R/utils-cache.R +++ b/R/utils-cache.R @@ -41,7 +41,7 @@ is_cached <- function(text, #' @param transformers A list of transformer functions, because we can only #' know if text is already correct if we know which transformer function it #' should be styled with. -#' @param more_args A named vector coercible to it character that determine the +#' @param more_specs A named vector coercible to it character that determine the #' styling but are style guide independent, such as `include_roxygen_examples` #' or `base_indention`. #' @details diff --git a/_pkgdown.yml b/_pkgdown.yml index c6dac5a27..1127f11a5 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -78,3 +78,4 @@ articles: contents: - caching - customizing_styler + - distribute_custom_style_guide diff --git a/inst/WORDLIST b/inst/WORDLIST index 5caeaf2ef..e15067497 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -111,6 +111,7 @@ macOS magrittr md MERCHANTABILITY +mlr Müller mutli na @@ -121,6 +122,7 @@ NONINFRINGEMENT nph NUM oldrel +oneliner os ourself packagemanager diff --git a/man/cache_by_expression.Rd b/man/cache_by_expression.Rd index c5dbfb39f..32900c9e5 100644 --- a/man/cache_by_expression.Rd +++ b/man/cache_by_expression.Rd @@ -12,6 +12,10 @@ cache_by_expression(text, transformers, more_specs) \item{transformers}{A list of transformer functions, because we can only know if text is already correct if we know which transformer function it should be styled with.} + +\item{more_specs}{A named vector coercible to it character that determine the +styling but are style guide independent, such as \code{include_roxygen_examples} +or \code{base_indention}.} } \description{ Splits \code{text} into expressions and adds these to the cache. Note that diff --git a/man/cache_make_key.Rd b/man/cache_make_key.Rd index dc9f4bd1c..618dc012b 100644 --- a/man/cache_make_key.Rd +++ b/man/cache_make_key.Rd @@ -14,7 +14,7 @@ approach used by styler does not cache input, but styled code.} know if text is already correct if we know which transformer function it should be styled with.} -\item{more_args}{A named vector coercible to it character that determine the +\item{more_specs}{A named vector coercible to it character that determine the styling but are style guide independent, such as \code{include_roxygen_examples} or \code{base_indention}.} } diff --git a/man/cache_write.Rd b/man/cache_write.Rd index 286e9abe0..190621f2c 100644 --- a/man/cache_write.Rd +++ b/man/cache_write.Rd @@ -13,6 +13,10 @@ approach used by styler does not cache input, but styled code.} \item{transformers}{A list of transformer functions, because we can only know if text is already correct if we know which transformer function it should be styled with.} + +\item{more_specs}{A named vector coercible to it character that determine the +styling but are style guide independent, such as \code{include_roxygen_examples} +or \code{base_indention}.} } \description{ Write to the cache diff --git a/vignettes/customizing_styler.Rmd b/vignettes/customizing_styler.Rmd index 75d40b192..b5024ee8f 100644 --- a/vignettes/customizing_styler.Rmd +++ b/vignettes/customizing_styler.Rmd @@ -8,7 +8,8 @@ vignette: > --- 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. +define your own style guide and format code according to it. How to distribute +a custom style guide is described in `vignette('distribute_custom_style_guide')` # How styler works diff --git a/vignettes/distribute_custom_style_guide.Rmd b/vignettes/distribute_custom_style_guide.Rmd new file mode 100644 index 000000000..c71d04cd1 --- /dev/null +++ b/vignettes/distribute_custom_style_guide.Rmd @@ -0,0 +1,73 @@ +--- +title: "distribute_custom_style_guide" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{distribute_custom_style_guide} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +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()`. + +## Reference implementations + +There are two packages that implement a third-party style guide: + +* [lorenzwalthert/oneliner](https://github.com/lorenzwalthert/oneliner) +* [mlr-org/styler.mlr](https://github.com/mlr-org/styler.mlr) + +## Design patterns + +The style guides mentioned above follow best practices and can serve as a good +and rather minimal example of how to implement your own style guide. Most +importantly, they: + +* export all functions that {styler} exports, but the `style` argument set + to the custom style guide, plus custom style guides. + The advantage of this is that you can use that namespace as a drop-in + replacement for styler everywhere. In particular, if you want to use the + tidyverse style guide, use `styler::style_pkg()`, if you want to use a + third-party style guide, use the other namespace, e.g. `styler.mlr::style_pkg()` +* depend on {styler} and use styler internals via `:::`. + This implies that they won't make it to CRAN because packages calling private + methods from other packages don't pass CRAN checks. The only way around this + would be to export some styler internals, e.g. via a {styler.infra} package, + but that would be a lot of work on our side. Another alternative for + developers might be to use https://github.com/wch/staticimports. +* implement unit tests following {styler}'s testing convention with `*-in.R` and + `*-out.R` files that are checked with `styler:::test_collection()`. + + +When creating a custom style guide and distribute it, we want to quickly recall +important arguments for `create_style_guide()` from the docs: + +* `style_guide_name`, `style_guide_version` and `more_specs_style_guide`: + These arguments are relevant for caching and make sure the user's cache is + invalidated on releasing a new version. The documentation specifies how to + set these arguments. +* `transformers_drop`: This argument can be created with `specify_transformers_drop()` + to define conditions under which a transformer can be removed from the style + guide without an effect on the result. This makes styler faster. For example, + if you have a transformer that removes the token `;` and replaces it with a + line break, it is only required if the code to style contains this token. + Since this will hardly be the case for people who adhere to the tidyverse + style guide, we formulate such a rule like this + +```{r} +styler::specify_transformers_drop( + spaces = list(style_space_around_tilde = "'~'"), + tokens = list(resolve_semicolon = "';'") +) +``` + +Where the name must correspond to the transformer function in question and the +value is the token that must be absent in order to drop the transformer. From 1b8bc505b609a66b9229746e8de2996ca41ae5a9 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 7 Oct 2021 18:03:28 +0200 Subject: [PATCH 022/114] Update R/utils-cache.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Maëlle Salmon --- R/utils-cache.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils-cache.R b/R/utils-cache.R index e31a5f233..4c515b91f 100644 --- a/R/utils-cache.R +++ b/R/utils-cache.R @@ -41,7 +41,7 @@ is_cached <- function(text, #' @param transformers A list of transformer functions, because we can only #' know if text is already correct if we know which transformer function it #' should be styled with. -#' @param more_specs A named vector coercible to it character that determine the +#' @param more_specs A named vector coercible to character that determines the #' styling but are style guide independent, such as `include_roxygen_examples` #' or `base_indention`. #' @details From 71fab768dba6afe506e077f0f3742dbcffd02ed3 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Fri, 8 Oct 2021 20:54:03 +0200 Subject: [PATCH 023/114] also recognize lintr ignore markers --- NEWS.md | 4 +++ R/nest.R | 14 +++++--- R/stylerignore.R | 8 ++--- R/zzz.R | 4 +-- inst/WORDLIST | 1 + man/add_stylerignore.Rd | 2 +- man/stylerignore.Rd | 14 +++++--- tests/testthat/test-stylerignore.R | 57 ++++++++++++++++++++++++++++++ 8 files changed, 87 insertions(+), 17 deletions(-) diff --git a/NEWS.md b/NEWS.md index dc6b65b2d..9e3cb38fa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,10 @@ # styler 1.6.2.9000 (Development version) +* multiple stylerignore patterns can be specified at once and lintr markers + `# nolint`, `# nolint start` and `# nolint end` are now by default recognized + in addition to `# styler: off` and `# styler: on` (#849). + # styler 1.6.2 * clean up cache files older than one week (#842). diff --git a/R/nest.R b/R/nest.R index 9fa5d96da..071175b9a 100644 --- a/R/nest.R +++ b/R/nest.R @@ -159,20 +159,24 @@ find_pos_id_to_keep <- function(pd) { #' [detected by styler](https://styler.r-lib.org/articles/detect-alignment.html), #' making stylerignore redundant. See a few illustrative examples below. #' @details -#' Styling is on by default when you run styler. +#' Styling is on for all lines by default when you run styler. #' #' - To mark the start of a sequence where you want to turn styling off, use -#' `# styler: off`. +#' `# styler: off`. For styler version > 1.6.2, `# nolint` and `#nolint start` +#' also works by default. #' - To mark the end of this sequence, put `# styler: on` in your code. After -#' that line, styler will again format your code. +#' that line, styler will again format your code. For styler version > 1.6.2, +#' `#nolint end` also works by default. #' - To ignore an inline statement (i.e. just one line), place `# styler: off` #' at the end of the line. Note that inline statements cannot contain other #' comments apart from the marker, i.e. a line like -#' `1 # comment # styler: off` won't be ignored. +#' `1 # comment # styler: off` won't be ignored. For styler version > 1.6.2, +#' `# nolint` and `#nolint start` also works. #' #' To use something else as start and stop markers, set the R options #' `styler.ignore_start` and -#' `styler.ignore_stop` using [options()]. If you want these +#' `styler.ignore_stop` using [options()]. For styler version > 1.6.2, the +#' option supports character vectors longer than one. If you want these #' settings to persist over multiple R sessions, consider setting them in your #' R profile, e.g. with `usethis::edit_rprofile()`. #' @name stylerignore diff --git a/R/stylerignore.R b/R/stylerignore.R index 7a107bf6e..2a4995d54 100644 --- a/R/stylerignore.R +++ b/R/stylerignore.R @@ -48,13 +48,13 @@ env_add_stylerignore <- function(pd_flat) { #' #' See examples in [stylerignore]. Note that you should reuse the stylerignore #' column to compute switch points or similar and not a plain -#' `pd$text == option_read("styler.ignore_start")` because that will fail to +#' `pd$text %in% option_read("styler.ignore_start")` because that will fail to #' give correct switch points in the case stylerignore sequences are invalid. #' @param pd_flat A parse table. #' @keywords internal add_stylerignore <- function(pd_flat) { parse_text <- trimws(pd_flat$text) - start_candidate <- parse_text == option_read("styler.ignore_start") + start_candidate <- parse_text %in% option_read("styler.ignore_start") pd_flat$stylerignore <- rep(FALSE, length(start_candidate)) env_current$any_stylerignore <- any(start_candidate) if (!env_current$any_stylerignore) { @@ -64,7 +64,7 @@ add_stylerignore <- function(pd_flat) { pd_flat_lat_line1 <- lag(pd_flat$line2, default = 0) on_same_line <- pd_flat$line1 == pd_flat_lat_line1 cumsum_start <- cumsum(start_candidate & !on_same_line) - cumsum_stop <- cumsum(parse_text == option_read("styler.ignore_stop")) + cumsum_stop <- cumsum(parse_text %in% option_read("styler.ignore_stop")) pd_flat$indicator_off <- cumsum_start + cumsum_stop is_invalid <- cumsum_start - cumsum_stop < 0 | cumsum_start - cumsum_stop > 1 if (any(is_invalid)) { @@ -105,7 +105,7 @@ apply_stylerignore <- function(flattened_pd) { colnames_required_apply_stylerignore <- c( "pos_id_", "lag_newlines", "lag_spaces", "text", "first_pos_id_in_segment" ) - # cannot rely on flattened_pd$text == option_read("styler.ignore_start") + # cannot rely on flattened_pd$text %in% option_read("styler.ignore_start") # because if the marker logic is not correct (twice off in a row), we'll # get it wrong. to_ignore <- flattened_pd$stylerignore == TRUE diff --git a/R/zzz.R b/R/zzz.R index 2917d4f6f..e91d64956 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -5,8 +5,8 @@ styler.addins_style_transformer = "styler::tidyverse_style()", styler.cache_name = styler_version, styler.colored_print.vertical = TRUE, - styler.ignore_start = "# styler: off", - styler.ignore_stop = "# styler: on", + styler.ignore_start = c("# styler: off", "# nolint", "nolint start"), + styler.ignore_stop = c("# styler: on", "# nolint end"), styler.quiet = FALSE, styler.test_dir_writable = TRUE ) diff --git a/inst/WORDLIST b/inst/WORDLIST index 5caeaf2ef..c132c8084 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -103,6 +103,7 @@ LF LIBS lifecycle Ligges +lintr linux lorenz lorenzwalthert diff --git a/man/add_stylerignore.Rd b/man/add_stylerignore.Rd index d00725f3b..e9262cc31 100644 --- a/man/add_stylerignore.Rd +++ b/man/add_stylerignore.Rd @@ -24,7 +24,7 @@ the R options \code{styler.ignore_start} and \code{styler.ignore_stop}. See examples in \link{stylerignore}. Note that you should reuse the stylerignore column to compute switch points or similar and not a plain -\code{pd$text == option_read("styler.ignore_start")} because that will fail to +\code{pd$text \%in\% option_read("styler.ignore_start")} because that will fail to give correct switch points in the case stylerignore sequences are invalid. } \keyword{internal} diff --git a/man/stylerignore.Rd b/man/stylerignore.Rd index abf91f23a..e1362b577 100644 --- a/man/stylerignore.Rd +++ b/man/stylerignore.Rd @@ -10,21 +10,25 @@ for \verb{styler > 1.2.0}, some alignment is making stylerignore redundant. See a few illustrative examples below. } \details{ -Styling is on by default when you run styler. +Styling is on for all lines by default when you run styler. \itemize{ \item To mark the start of a sequence where you want to turn styling off, use -\verb{# styler: off}. +\verb{# styler: off}. For styler version > 1.6.2, \verb{# nolint} and \verb{#nolint start} +also works by default. \item To mark the end of this sequence, put \verb{# styler: on} in your code. After -that line, styler will again format your code. +that line, styler will again format your code. For styler version > 1.6.2, +\verb{#nolint end} also works by default. \item To ignore an inline statement (i.e. just one line), place \verb{# styler: off} at the end of the line. Note that inline statements cannot contain other comments apart from the marker, i.e. a line like -\code{1 # comment # styler: off} won't be ignored. +\code{1 # comment # styler: off} won't be ignored. For styler version > 1.6.2, +\verb{# nolint} and \verb{#nolint start} also works. } To use something else as start and stop markers, set the R options \code{styler.ignore_start} and -\code{styler.ignore_stop} using \code{\link[=options]{options()}}. If you want these +\code{styler.ignore_stop} using \code{\link[=options]{options()}}. For styler version > 1.6.2, the +option supports character vectors longer than one. If you want these settings to persist over multiple R sessions, consider setting them in your R profile, e.g. with \code{usethis::edit_rprofile()}. } diff --git a/tests/testthat/test-stylerignore.R b/tests/testthat/test-stylerignore.R index c3c1af875..708b77f17 100644 --- a/tests/testthat/test-stylerignore.R +++ b/tests/testthat/test-stylerignore.R @@ -77,6 +77,63 @@ test_that("works with other markers", { ) }) +test_that("works with multiple markers", { + expect_equal( + withr::with_options( + list( + styler.ignore_start = c("# startignore", "#lintstart"), + styler.ignore_stop = "# xxx" + ), + { + style_text(c( + "1+1", + "#lintstart", + "1+1", + "# xxx", + "1+1" + )) %>% + as.character() + } + ), + c("1 + 1", "#lintstart", "1+1", "# xxx", "1 + 1") + ) +}) + +test_that("works with multiple markers", { + expect_equal( + withr::with_options( + list( + styler.ignore_start = "# startignore", + styler.ignore_stop = c("# xxx", "# lintstop") + ), + { + style_text(c( + "1+1", + "# startignore", + "1+1", + "# lintstop", + "1+1" + )) %>% + as.character() + } + ), + c("1 + 1", "# startignore", "1+1", "# lintstop", "1 + 1") + ) +}) + +test_that("works for multiple markers inline", { + withr::local_options(styler.ignore_start = "# noeq", ) + expect_equal( + style_text(c( + "1+1", + "1+1# noeq", + "1+1" + )) %>% + as.character(), + c("1 + 1", "1+1# noeq", "1 + 1") + ) +}) + test_that("works with other markers", { expect_warning( withr::with_options( From 3bc088ac55aa50c53f0b06aa272ef2f6b1ec5032 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Fri, 8 Oct 2021 20:08:17 +0200 Subject: [PATCH 024/114] stylerignore should be respected fr alignemnt detection --- NEWS.md | 1 + R/detect-alignment.R | 10 +- tests/testthat/stylerignore/alignment-in.R | 5 + tests/testthat/stylerignore/alignment-in_tree | 110 ++++++++++++++++++ tests/testthat/stylerignore/alignment-out.R | 5 + tests/testthat/test-stylerignore.R | 6 + 6 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/stylerignore/alignment-in.R create mode 100644 tests/testthat/stylerignore/alignment-in_tree create mode 100644 tests/testthat/stylerignore/alignment-out.R diff --git a/NEWS.md b/NEWS.md index dc6b65b2d..bdd0a9d35 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # styler 1.6.2.9000 (Development version) +* Alignment detection respects stylerignore (#850). # styler 1.6.2 diff --git a/R/detect-alignment.R b/R/detect-alignment.R index 2143ac5cb..49093011f 100644 --- a/R/detect-alignment.R +++ b/R/detect-alignment.R @@ -49,6 +49,10 @@ token_is_on_aligned_line <- function(pd_flat) { pd_flat$lag_newlines <- pd_flat$pos_id <- NULL pd_flat$.lag_spaces <- lag(pd_flat$spaces) pd_by_line <- split(pd_flat, line_idx) + pd_by_line[purrr::map_lgl(pd_by_line, ~ any(.x$stylerignore))] <- NULL + if (length(pd_by_line) < 1) { + return(TRUE) + } last_line_is_closing_brace_only <- nrow(last(pd_by_line)) == 1 relevant_idx <- seq2(2, ifelse(last_line_is_closing_brace_only, length(pd_by_line) - 1, @@ -86,7 +90,11 @@ token_is_on_aligned_line <- function(pd_flat) { } pd_by_line <- alignment_drop_comments(pd_by_line) %>% - alignment_ensure_no_closing_brace(last_line_is_closing_brace_only) %>% + alignment_ensure_no_closing_brace(last_line_is_closing_brace_only) + if (length(pd_by_line) < 1) { + return(TRUE) + } + pd_by_line <- pd_by_line %>% alignment_ensure_trailing_comma() # now, pd only contains arguments separated by values, ideal for iterating # over columns. diff --git a/tests/testthat/stylerignore/alignment-in.R b/tests/testthat/stylerignore/alignment-in.R new file mode 100644 index 000000000..b128cbac5 --- /dev/null +++ b/tests/testthat/stylerignore/alignment-in.R @@ -0,0 +1,5 @@ +ps( + interaction_constraints = p_uty(tgs = "train"), + monotone_constraints = p_uty(dfault = 0, tags = c("train", "control"), custom_check = function(x) { checkmate::check_integerish(x, lower = -1, upper = 1, any.missing = FALSE) }), # styler: off + normalize_type = p_fct(c("tee", "forest"), default = "tree", tags = "train"), +) diff --git a/tests/testthat/stylerignore/alignment-in_tree b/tests/testthat/stylerignore/alignment-in_tree new file mode 100644 index 000000000..18ae34374 --- /dev/null +++ b/tests/testthat/stylerignore/alignment-in_tree @@ -0,0 +1,110 @@ +ROOT (token: short_text [lag_newlines/spaces] {pos_id}) + °--expr: ps( + [0/0] {1} + ¦--expr: ps [0/0] {3} + ¦ °--SYMBOL_FUNCTION_CALL: ps [0/0] {2} + ¦--'(': ( [0/2] {4} + ¦--SYMBOL_SUB: inter [1/1] {5} + ¦--EQ_SUB: = [0/1] {6} + ¦--expr: p_uty [0/0] {7} + ¦ ¦--expr: p_uty [0/0] {9} + ¦ ¦ °--SYMBOL_FUNCTION_CALL: p_uty [0/0] {8} + ¦ ¦--'(': ( [0/0] {10} + ¦ ¦--SYMBOL_SUB: tgs [0/1] {11} + ¦ ¦--EQ_SUB: = [0/1] {12} + ¦ ¦--expr: "trai [0/0] {14} + ¦ ¦ °--STR_CONST: "trai [0/0] {13} + ¦ °--')': ) [0/0] {15} + ¦--',': , [0/2] {16} + ¦--SYMBOL_SUB: monot [1/4] {17} + ¦--EQ_SUB: = [0/1] {18} + ¦--expr: p_uty [0/0] {19} + ¦ ¦--expr: p_uty [0/0] {21} + ¦ ¦ °--SYMBOL_FUNCTION_CALL: p_uty [0/0] {20} + ¦ ¦--'(': ( [0/0] {22} + ¦ ¦--SYMBOL_SUB: dfaul [0/1] {23} + ¦ ¦--EQ_SUB: = [0/1] {24} + ¦ ¦--expr: 0 [0/0] {26} + ¦ ¦ °--NUM_CONST: 0 [0/0] {25} + ¦ ¦--',': , [0/1] {27} + ¦ ¦--SYMBOL_SUB: tags [0/1] {28} + ¦ ¦--EQ_SUB: = [0/1] {29} + ¦ ¦--expr: c("tr [0/0] {30} + ¦ ¦ ¦--expr: c [0/0] {32} + ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: c [0/0] {31} + ¦ ¦ ¦--'(': ( [0/0] {33} + ¦ ¦ ¦--expr: "trai [0/0] {35} + ¦ ¦ ¦ °--STR_CONST: "trai [0/0] {34} + ¦ ¦ ¦--',': , [0/1] {36} + ¦ ¦ ¦--expr: "cont [0/0] {38} + ¦ ¦ ¦ °--STR_CONST: "cont [0/0] {37} + ¦ ¦ °--')': ) [0/0] {39} + ¦ ¦--',': , [0/1] {40} + ¦ ¦--SYMBOL_SUB: custo [0/1] {41} + ¦ ¦--EQ_SUB: = [0/1] {42} + ¦ ¦--expr: funct [0/0] {43} + ¦ ¦ ¦--FUNCTION: funct [0/0] {44} + ¦ ¦ ¦--'(': ( [0/0] {45} + ¦ ¦ ¦--SYMBOL_FORMALS: x [0/0] {46} + ¦ ¦ ¦--')': ) [0/1] {47} + ¦ ¦ °--expr: { ch [0/0] {48} + ¦ ¦ ¦--'{': { [0/2] {49} + ¦ ¦ ¦--expr: check [0/1] {50} + ¦ ¦ ¦ ¦--expr: check [0/0] {51} + ¦ ¦ ¦ ¦ ¦--SYMBOL_PACKAGE: check [0/0] {52} + ¦ ¦ ¦ ¦ ¦--NS_GET: :: [0/0] {53} + ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: check [0/0] {54} + ¦ ¦ ¦ ¦--'(': ( [0/0] {55} + ¦ ¦ ¦ ¦--expr: x [0/0] {57} + ¦ ¦ ¦ ¦ °--SYMBOL: x [0/0] {56} + ¦ ¦ ¦ ¦--',': , [0/1] {58} + ¦ ¦ ¦ ¦--SYMBOL_SUB: lower [0/1] {59} + ¦ ¦ ¦ ¦--EQ_SUB: = [0/1] {60} + ¦ ¦ ¦ ¦--expr: -1 [0/0] {61} + ¦ ¦ ¦ ¦ ¦--'-': - [0/0] {62} + ¦ ¦ ¦ ¦ °--expr: 1 [0/0] {64} + ¦ ¦ ¦ ¦ °--NUM_CONST: 1 [0/0] {63} + ¦ ¦ ¦ ¦--',': , [0/1] {65} + ¦ ¦ ¦ ¦--SYMBOL_SUB: upper [0/1] {66} + ¦ ¦ ¦ ¦--EQ_SUB: = [0/1] {67} + ¦ ¦ ¦ ¦--expr: 1 [0/0] {69} + ¦ ¦ ¦ ¦ °--NUM_CONST: 1 [0/0] {68} + ¦ ¦ ¦ ¦--',': , [0/1] {70} + ¦ ¦ ¦ ¦--SYMBOL_SUB: any.m [0/1] {71} + ¦ ¦ ¦ ¦--EQ_SUB: = [0/1] {72} + ¦ ¦ ¦ ¦--expr: FALSE [0/0] {74} + ¦ ¦ ¦ ¦ °--NUM_CONST: FALSE [0/0] {73} + ¦ ¦ ¦ °--')': ) [0/0] {75} + ¦ ¦ °--'}': } [0/0] {76} + ¦ °--')': ) [0/0] {77} + ¦--',': , [0/1] {78} + ¦--COMMENT: # sty [0/2] {79} + ¦--SYMBOL_SUB: norma [1/10] {80} + ¦--EQ_SUB: = [0/1] {81} + ¦--expr: p_fct [0/0] {82} + ¦ ¦--expr: p_fct [0/0] {84} + ¦ ¦ °--SYMBOL_FUNCTION_CALL: p_fct [0/0] {83} + ¦ ¦--'(': ( [0/0] {85} + ¦ ¦--expr: c("te [0/0] {86} + ¦ ¦ ¦--expr: c [0/0] {88} + ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: c [0/0] {87} + ¦ ¦ ¦--'(': ( [0/0] {89} + ¦ ¦ ¦--expr: "tee" [0/0] {91} + ¦ ¦ ¦ °--STR_CONST: "tee" [0/0] {90} + ¦ ¦ ¦--',': , [0/1] {92} + ¦ ¦ ¦--expr: "fore [0/0] {94} + ¦ ¦ ¦ °--STR_CONST: "fore [0/0] {93} + ¦ ¦ °--')': ) [0/0] {95} + ¦ ¦--',': , [0/1] {96} + ¦ ¦--SYMBOL_SUB: defau [0/1] {97} + ¦ ¦--EQ_SUB: = [0/1] {98} + ¦ ¦--expr: "tree [0/0] {100} + ¦ ¦ °--STR_CONST: "tree [0/0] {99} + ¦ ¦--',': , [0/1] {101} + ¦ ¦--SYMBOL_SUB: tags [0/1] {102} + ¦ ¦--EQ_SUB: = [0/1] {103} + ¦ ¦--expr: "trai [0/0] {105} + ¦ ¦ °--STR_CONST: "trai [0/0] {104} + ¦ °--')': ) [0/0] {106} + ¦--',': , [0/0] {107} + °--')': ) [1/0] {108} diff --git a/tests/testthat/stylerignore/alignment-out.R b/tests/testthat/stylerignore/alignment-out.R new file mode 100644 index 000000000..b128cbac5 --- /dev/null +++ b/tests/testthat/stylerignore/alignment-out.R @@ -0,0 +1,5 @@ +ps( + interaction_constraints = p_uty(tgs = "train"), + monotone_constraints = p_uty(dfault = 0, tags = c("train", "control"), custom_check = function(x) { checkmate::check_integerish(x, lower = -1, upper = 1, any.missing = FALSE) }), # styler: off + normalize_type = p_fct(c("tee", "forest"), default = "tree", tags = "train"), +) diff --git a/tests/testthat/test-stylerignore.R b/tests/testthat/test-stylerignore.R index c3c1af875..bf3950b4e 100644 --- a/tests/testthat/test-stylerignore.R +++ b/tests/testthat/test-stylerignore.R @@ -120,3 +120,9 @@ test_that("no token added or removed in complex case", { transformer = style_text ), NA) }) + +test_that("stylerignore sequences are respected in alignment detection", { + expect_warning(test_collection("stylerignore", "alignment", + transformer = style_text + ), NA) +}) From 34069bd7461055ce367b1169ccb4bf7059633f75 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Fri, 8 Oct 2021 22:31:46 +0200 Subject: [PATCH 025/114] add dot --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 223300158..5396c647c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ # styler 1.6.2.9000 (Development version) * Alignment detection respects stylerignore (#850). -* Enable pre-commit.ci (#843) +* Enable pre-commit.ci (#843). # styler 1.6.2 From cb0fc767a50badaab956946d501b3c2bd7480bb1 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 9 Oct 2021 22:53:16 +0200 Subject: [PATCH 026/114] add blog post on quick customization as vignette, Edis proposed by Maelle for main vignette --- _pkgdown.yml | 3 +- inst/WORDLIST | 1 + vignettes/customizing_styler.Rmd | 7 +- vignettes/distribute_custom_style_guide.Rmd | 22 ++- vignettes/remove_rules.Rmd | 173 ++++++++++++++++++++ vignettes/styler.Rmd | 7 +- 6 files changed, 200 insertions(+), 13 deletions(-) create mode 100644 vignettes/remove_rules.Rmd diff --git a/_pkgdown.yml b/_pkgdown.yml index 1127f11a5..f35b710a6 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -76,6 +76,7 @@ articles: - title: Developers navbar: Developers contents: - - caching + - remove_rules - customizing_styler - distribute_custom_style_guide + - caching diff --git a/inst/WORDLIST b/inst/WORDLIST index e15067497..1c5fc055b 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -168,6 +168,7 @@ rmd Rmd rnw Rnw +roadmap roclet roclets rootPath diff --git a/vignettes/customizing_styler.Rmd b/vignettes/customizing_styler.Rmd index b5024ee8f..82a17638b 100644 --- a/vignettes/customizing_styler.Rmd +++ b/vignettes/customizing_styler.Rmd @@ -8,8 +8,11 @@ vignette: > --- 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. How to distribute -a custom style guide is described in `vignette('distribute_custom_style_guide')` +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_guide")`. # How styler works diff --git a/vignettes/distribute_custom_style_guide.Rmd b/vignettes/distribute_custom_style_guide.Rmd index c71d04cd1..164eba803 100644 --- a/vignettes/distribute_custom_style_guide.Rmd +++ b/vignettes/distribute_custom_style_guide.Rmd @@ -1,8 +1,8 @@ --- -title: "distribute_custom_style_guide" +title: "Distribute custom style guides" output: rmarkdown::html_vignette vignette: > - %\VignetteIndexEntry{distribute_custom_style_guide} + %\VignetteIndexEntry{Distribute custom style guides} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- @@ -15,7 +15,7 @@ knitr::opts_chunk$set( ``` 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 +on `vignette("customizing_styler")` and assumes you understand how to create a style guide with `create_style_guide()`. ## Reference implementations @@ -29,7 +29,7 @@ There are two packages that implement a third-party style guide: The style guides mentioned above follow best practices and can serve as a good and rather minimal example of how to implement your own style guide. Most -importantly, they: +importantly, these two packages: * export all functions that {styler} exports, but the `style` argument set to the custom style guide, plus custom style guides. @@ -37,12 +37,16 @@ importantly, they: replacement for styler everywhere. In particular, if you want to use the tidyverse style guide, use `styler::style_pkg()`, if you want to use a third-party style guide, use the other namespace, e.g. `styler.mlr::style_pkg()` -* depend on {styler} and use styler internals via `:::`. - This implies that they won't make it to CRAN because packages calling private - methods from other packages don't pass CRAN checks. The only way around this +* depend on {styler} and use {styler} internals via `:::`. + These internals are subject to change without prior notice, which is why the + packages also have unit tests. Also note that importing internals from another + package means your package can't be added to CRAN because packages calling + private methods from other packages don't pass CRAN checks. The only way around this would be to export some styler internals, e.g. via a {styler.infra} package, - but that would be a lot of work on our side. Another alternative for - developers might be to use https://github.com/wch/staticimports. + but that would be a lot of work on our side and therefore not currently on the + roadmap. Another alternative for + developers might be to use https://github.com/wch/staticimports, which we have + not explored so far. * implement unit tests following {styler}'s testing convention with `*-in.R` and `*-out.R` files that are checked with `styler:::test_collection()`. diff --git a/vignettes/remove_rules.Rmd b/vignettes/remove_rules.Rmd new file mode 100644 index 000000000..90d306ef1 --- /dev/null +++ b/vignettes/remove_rules.Rmd @@ -0,0 +1,173 @@ +--- +title: "Remove rules" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Remove rules} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r, echo = FALSE, include = FALSE} +options(styler.colored_print.vertical = FALSE) +``` + +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](http://styler.r-lib.org/reference/tidyverse_style.html) for + the function `tidyverse_style()`, which returns the transformer functions that + prettify your code. Most of these options are explained in `vignette("styler")`. + +- If you can't get styler behaving the way you want using the arguments of + `tidyverse_style()`, you have another option, which is described in a + `vignette("customizing_styler")`: Creating your own style guide from scratch. + Yes, I admit, it's pretty long and if you don't want to become a + *styler expert*, it may be a little bit overwhelming. + +- If you don't care about how to create new rules but you simply want to *remove* + a rule, I have good news for you: There is a quick way to do it. And that's + what the remainder of this vignette focuses on. + +Once you are happy with your style guide, you might ant to have a look at how to +distribute it, which is described in +`vignette("distribute_custom_style_guide")`. + +# Theory + +Here are the steps required to deactivate a rule you don't like + +- Figure out which transformer function in the transformers returned by + `tidyerse_style()` corresponds to the rule you want to remove. + +- Set that element in the list to `NULL`, which is equivalent to removing it. + +- Pass the list to `style_text` as a transformer. + +# Practice + +Lets assume you want to remove the rule that turns `=` into `<-` for assignment. +That means you want + +``` +string = "hi there" +``` + +to remain unchanged after applying styler. This is not the case if you use the +default style guide of styler: + +```{r, comment = ""} +library(styler) +style_text("string = 'hi there'") +``` + +So you need to figure out which rule is responsible for this. Let's check the +transformer categories used with the tidyverse style guide. + +```{r} +transformers <- tidyverse_style() +names(transformers) +``` + +From the aforementioned +[vignette](http://styler.r-lib.org/articles/customizing_styler.html): + +> We note that there are different types of transformer functions. initialize +initializes some variables in the nested parse table (so it is not actually a +transformer), and the other elements modify either spacing, line breaks or +tokens. use_raw_indention is not a function, it is just an option. + +Now, we can look at the names of the rules that are sub-elements of the +transformer categories. + +```{r} +library(magrittr) +levels <- c("space", "line_break", "indention", "token") +purrr::map( + levels, + ~ names(transformers[[.x]]) +) %>% + purrr::set_names(levels) +``` + +Spotted the rule we want to get rid of? It's under `token` and it's called +`force_assignment_op`. I agree, we could have chosen a better name. If you are +not sure if you can guess from the name of the rule what it does you can also +have a look at the function declaration of this (unexported) function. + +```{r} +styler:::force_assignment_op +``` + +Next, you simply set that element to `NULL`. + +```{r} +transformers$token$force_assignment_op <- NULL +``` + +And you can use the modified transformer list as input to `style_text()` + +```{r} +style_text("string = 'hi there'", transformers = transformers) +``` + +If you want to use it the same way as `tidyverse_style()`, here's the last step: + +```{r} +eq_assign_style <- function(...) { + transformers <- tidyverse_style(...) + transformers$token$force_assignment_op <- NULL + transformers +} + +style_text("string = 'hi there'", style = eq_assign_style) +``` + + +That's it. Note that the transformer functions and how they are returned by +`tidyverse_style()` is not part of the exposed API. This means that the order, +the naming etc. may change. Also, remember we did not add a rule to replace `<-` +with `=`, but we only removed a rule to replace `=` with `<-`, so `<-` won't be +touched: + +```{r} +style_text("string <- 'hi there'", style = eq_assign_style) +``` + +If you want to turn `<-` into `=`, you need to add a rule as described in +`vignette("customizing_styler")`. + +# Some other rules and their transformers + +* You don't like multi-line ifelse statements getting wrapped around curly + braces: `transformers$token$wrap_if_else_multi_line_in_curly`. + +* You don't like multi-line calls to be broken before the first named argument: + `transformers$line_break$set_line_break_after_opening_if_call_is_multi_line` + (interacting with + `transformers$line_break$set_line_break_before_closing_call`). + +* You don't like the line being broken after the pipe: + `transformers$line_break$add_line_break_after_pipe` + +* You don't like single quotes to be replaced by double quotes: + `transformers$space$fix_quotes`. + +* You don't like comments to start with one space: + `transformers$space$start_comments_with_space` + +I think you get the idea. I nevertheless recommend using the [tidyverse style +guide](http://style.tidyverse.org/) as is since + +- it is a well-established, thought-through style. + +- using a consistent style (no matter which) reduces friction in the community. + +If you have questions, don't hesitate to create an issue in the GitHub repo. diff --git a/vignettes/styler.Rmd b/vignettes/styler.Rmd index 15f773a6c..677dd1700 100644 --- a/vignettes/styler.Rmd +++ b/vignettes/styler.Rmd @@ -235,4 +235,9 @@ style_text( These verse some (not all) configurations exposed in `style_file()` and friends as well as `tidyverse_style()`. If the above did not give you the flexibility you hoped for, your can create your own style guide and customize styler even -further, as described in `vignette("customizing_styler")`. +further: + +* either by removing rules from the tidyverse style guide as described in + `vignette("remove_rules")`. +* or by creating your own style guide from scratch as described in + `vignette("customizing_styler")`. From 373bb9cdb5046ef137cefab26426f53323b287ff Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sun, 10 Oct 2021 18:05:02 +0200 Subject: [PATCH 027/114] rename --- ..._custom_style_guide.Rmd => distribute_custom_style_guides.Rmd} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename vignettes/{distribute_custom_style_guide.Rmd => distribute_custom_style_guides.Rmd} (100%) diff --git a/vignettes/distribute_custom_style_guide.Rmd b/vignettes/distribute_custom_style_guides.Rmd similarity index 100% rename from vignettes/distribute_custom_style_guide.Rmd rename to vignettes/distribute_custom_style_guides.Rmd From 87a614cd8229d29f1a9cb4ba78a53310692cd6b5 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 22:19:18 +0200 Subject: [PATCH 028/114] bump From 493860100b7c6656705670954636682f7c0f1431 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 22:35:39 +0200 Subject: [PATCH 029/114] bump From 082f432ee96a118463990192f7b5461a32909424 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 22:38:18 +0200 Subject: [PATCH 030/114] see if serialization is problem --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2735cfe77..bbcc0ca5a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,6 +7,7 @@ repos: rev: v0.1.3.9127 hooks: - id: style-files + require_serial: True args: [--style_pkg=styler, --style_fun=tidyverse_style] exclude: > (?x)^( From c655f704c5b8cc094d8ad08c158b2704ab336841 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 22:43:29 +0200 Subject: [PATCH 031/114] bump From 81b0042bd059173b33d06007cfda1f7d9c83970c Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 22:54:36 +0200 Subject: [PATCH 032/114] bump From 6469b8964bea67aa3102fac2737b869abc6ba198 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 23:03:53 +0200 Subject: [PATCH 033/114] bump From 6bbfe8ad7e8962a38ed55ed73594d8a6b51f7db1 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 23:06:14 +0200 Subject: [PATCH 034/114] bump From 7c86be4f59a14abbd95acb961bb7e83d470735c6 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 23:08:24 +0200 Subject: [PATCH 035/114] bump From b9425c504982525cd3e9e0ee5dd8dfc615763fd6 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 23:13:26 +0200 Subject: [PATCH 036/114] bump From 0854dc19437e29be4ca66cbe44bc40de763415de Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 23:20:11 +0200 Subject: [PATCH 037/114] bump From 0137d404bc418cc7a8dc6ca30d57821b6d09eca2 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 25 Sep 2021 23:24:49 +0200 Subject: [PATCH 038/114] bump From 2d99dc12455a639347438eca9a04aa48db5cdce9 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sun, 3 Oct 2021 15:29:17 +0200 Subject: [PATCH 039/114] bump From 4ef6bc2207b8becc177b407cdfc3b5591bcb3b70 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sun, 3 Oct 2021 15:56:22 +0200 Subject: [PATCH 040/114] bump From 2829785d739546d1ad4920eea07aa09f3a42ceb1 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sun, 3 Oct 2021 15:58:05 +0200 Subject: [PATCH 041/114] bump2 From de290e5ba87735dc9100b1fc807ef93671612dfb Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sun, 3 Oct 2021 16:16:06 +0200 Subject: [PATCH 042/114] bump3 From 06e7a6bbd2ea6cec80fc6c69f5d6a5204375269d Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sun, 3 Oct 2021 16:19:47 +0200 Subject: [PATCH 043/114] try without serial --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bbcc0ca5a..2735cfe77 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,6 @@ repos: rev: v0.1.3.9127 hooks: - id: style-files - require_serial: True args: [--style_pkg=styler, --style_fun=tidyverse_style] exclude: > (?x)^( From 7bd7af0709ab0db765f0743dc0e9619268b431db Mon Sep 17 00:00:00 2001 From: Lorenz Date: Thu, 14 Oct 2021 19:55:21 +0200 Subject: [PATCH 044/114] fix refs --- _pkgdown.yml | 2 +- vignettes/customizing_styler.Rmd | 2 +- vignettes/remove_rules.Rmd | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/_pkgdown.yml b/_pkgdown.yml index f35b710a6..0857dd929 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -78,5 +78,5 @@ articles: contents: - remove_rules - customizing_styler - - distribute_custom_style_guide + - distribute_custom_style_guides - caching diff --git a/vignettes/customizing_styler.Rmd b/vignettes/customizing_styler.Rmd index 82a17638b..237009aa0 100644 --- a/vignettes/customizing_styler.Rmd +++ b/vignettes/customizing_styler.Rmd @@ -12,7 +12,7 @@ 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_guide")`. +in `vignette("distribute_custom_style_guides")`. # How styler works diff --git a/vignettes/remove_rules.Rmd b/vignettes/remove_rules.Rmd index 90d306ef1..b7f18b4ae 100644 --- a/vignettes/remove_rules.Rmd +++ b/vignettes/remove_rules.Rmd @@ -38,7 +38,7 @@ are multiple ways: Once you are happy with your style guide, you might ant to have a look at how to distribute it, which is described in -`vignette("distribute_custom_style_guide")`. +`vignette("distribute_custom_style_guides")`. # Theory From 31e7ad59c46e4a4ce0b678560e99d0ce00bb9c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Fri, 15 Oct 2021 10:35:34 +0200 Subject: [PATCH 045/114] Add another "hacking" tip --- vignettes/remove_rules.Rmd | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/vignettes/remove_rules.Rmd b/vignettes/remove_rules.Rmd index b7f18b4ae..00d9faeb2 100644 --- a/vignettes/remove_rules.Rmd +++ b/vignettes/remove_rules.Rmd @@ -144,6 +144,30 @@ style_text("string <- 'hi there'", style = eq_assign_style) If you want to turn `<-` into `=`, you need to add a rule as described in `vignette("customizing_styler")`. +If you have trouble identifying a rule based on rule names, + +* First write an example whose results is not the one you wanted; + +E.g + +```r +code <- " +f <- function () { + +return (1) +}" +``` + +is code that will have the first empty line in the function body removed by 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 `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 function made the change; + move the `print(pd)` or `browser()` call to another function if not. + * Once you've identified the culprit (in this case `style_line_break_around_curly`), + set it to `NULL` as shown earlier. + # Some other rules and their transformers * You don't like multi-line ifelse statements getting wrapped around curly From b70ba33fd3f7c07c3595a1b35ff8eca5df794cef Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Tue, 19 Oct 2021 18:14:38 +0200 Subject: [PATCH 046/114] improve (I think) --- vignettes/remove_rules.Rmd | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/vignettes/remove_rules.Rmd b/vignettes/remove_rules.Rmd index 00d9faeb2..964f6d127 100644 --- a/vignettes/remove_rules.Rmd +++ b/vignettes/remove_rules.Rmd @@ -146,9 +146,7 @@ If you want to turn `<-` into `=`, you need to add a rule as described in If you have trouble identifying a rule based on rule names, -* First write an example whose results is not the one you wanted; - -E.g +* First write an example whose results is not the one you wanted, e.g. ```r code <- " @@ -160,10 +158,11 @@ return (1) is code that will have the first empty line in the function body removed by 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 `print(pd)` or `browser()` call in the functions +* 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 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 function made the change; + `load_all()`, run your example, see if that function made the change. move the `print(pd)` or `browser()` call to another function if not. * Once you've identified the culprit (in this case `style_line_break_around_curly`), set it to `NULL` as shown earlier. From bfcbe261b5faf9214ad284ac2a215dc5f75d6cc9 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Tue, 19 Oct 2021 22:38:41 +0200 Subject: [PATCH 047/114] add ability to set cache root within R.cache --- NEWS.md | 3 +++ R/utils-cache.R | 10 +++++----- R/zzz.R | 1 + man/cache_by_expression.Rd | 2 +- man/cache_make_key.Rd | 2 +- man/cache_write.Rd | 2 +- man/is_cached.Rd | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3d6b665d4..6fe6ae1f5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,9 @@ * Alignment detection respects stylerignore (#850). * Add vignette on distributing style guide (#846). * Enable pre-commit.ci (#843). +* new R option `styler.cache_root` (defaulting to `"styler"`) that determines + the sub-directory under the {R.cache} cache directory that {styler} uses. Non- + default caches won't be cleaned up by {styler}. # styler 1.6.2 diff --git a/R/utils-cache.R b/R/utils-cache.R index 4c515b91f..98d4e7ae0 100644 --- a/R/utils-cache.R +++ b/R/utils-cache.R @@ -24,7 +24,7 @@ hash_standardize <- function(text) { is_cached <- function(text, transformers, more_specs, - cache_dir = cache_dir_default()) { + cache_dir = cache_dir()) { R.cache::generateCache( key = cache_make_key(text, transformers, more_specs), dirs = cache_dir @@ -111,7 +111,7 @@ cache_make_key <- function(text, transformers, more_specs) { #' @keywords internal cache_find_path <- function(cache_name = NULL) { cache_name <- cache_get_or_derive_name(cache_name) - R.cache::getCachePath(c("styler", cache_name)) + R.cache::getCachePath(cache_dir(cache_name)) } #' Check if a cache is activated @@ -173,7 +173,7 @@ cache_by_expression <- function(text, cache_write <- function(text, transformers, more_specs) { R.cache::generateCache( key = cache_make_key(text, transformers, more_specs), - dirs = cache_dir_default() + dirs = cache_dir() ) %>% file.create() } @@ -194,8 +194,8 @@ cache_get_or_derive_name <- function(cache_name) { cache_name } -cache_dir_default <- function() { - c("styler", cache_get_name()) +cache_dir <- function(cache_name = cache_get_name()) { + c(getOption("styler.cache_root", "styler"), cache_name) } diff --git a/R/zzz.R b/R/zzz.R index 2917d4f6f..408ddbe73 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -3,6 +3,7 @@ op <- options() op.styler <- list( styler.addins_style_transformer = "styler::tidyverse_style()", + styler.cache_root = "styler", styler.cache_name = styler_version, styler.colored_print.vertical = TRUE, styler.ignore_start = "# styler: off", diff --git a/man/cache_by_expression.Rd b/man/cache_by_expression.Rd index 32900c9e5..3ae78e774 100644 --- a/man/cache_by_expression.Rd +++ b/man/cache_by_expression.Rd @@ -13,7 +13,7 @@ cache_by_expression(text, transformers, more_specs) know if text is already correct if we know which transformer function it should be styled with.} -\item{more_specs}{A named vector coercible to it character that determine the +\item{more_specs}{A named vector coercible to character that determines the styling but are style guide independent, such as \code{include_roxygen_examples} or \code{base_indention}.} } diff --git a/man/cache_make_key.Rd b/man/cache_make_key.Rd index 618dc012b..ec1cdb9d8 100644 --- a/man/cache_make_key.Rd +++ b/man/cache_make_key.Rd @@ -14,7 +14,7 @@ approach used by styler does not cache input, but styled code.} know if text is already correct if we know which transformer function it should be styled with.} -\item{more_specs}{A named vector coercible to it character that determine the +\item{more_specs}{A named vector coercible to character that determines the styling but are style guide independent, such as \code{include_roxygen_examples} or \code{base_indention}.} } diff --git a/man/cache_write.Rd b/man/cache_write.Rd index 190621f2c..703ba5328 100644 --- a/man/cache_write.Rd +++ b/man/cache_write.Rd @@ -14,7 +14,7 @@ approach used by styler does not cache input, but styled code.} know if text is already correct if we know which transformer function it should be styled with.} -\item{more_specs}{A named vector coercible to it character that determine the +\item{more_specs}{A named vector coercible to character that determines the styling but are style guide independent, such as \code{include_roxygen_examples} or \code{base_indention}.} } diff --git a/man/is_cached.Rd b/man/is_cached.Rd index 1ef4e9783..33b948f24 100644 --- a/man/is_cached.Rd +++ b/man/is_cached.Rd @@ -4,7 +4,7 @@ \alias{is_cached} \title{Check if text is cached} \usage{ -is_cached(text, transformers, more_specs, cache_dir = cache_dir_default()) +is_cached(text, transformers, more_specs, cache_dir = cache_dir()) } \arguments{ \item{text, transformers, more_specs}{Passed to \code{\link[=cache_make_key]{cache_make_key()}} to generate From 14262d1131eb691d30c12aa0953d8346c5e4e8a8 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Tue, 19 Oct 2021 22:54:41 +0200 Subject: [PATCH 048/114] suggest cache name --- NEWS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 6fe6ae1f5..5d2ac9e83 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,7 +5,8 @@ * Enable pre-commit.ci (#843). * new R option `styler.cache_root` (defaulting to `"styler"`) that determines the sub-directory under the {R.cache} cache directory that {styler} uses. Non- - default caches won't be cleaned up by {styler}. + default caches won't be cleaned up by {styler}. We suggest `"styler-perm"` + (also used by {precommit}). # styler 1.6.2 From 0d48ce2509876d1e52af476fa094e9998fb8c38c Mon Sep 17 00:00:00 2001 From: Lorenz Date: Tue, 19 Oct 2021 23:12:43 +0200 Subject: [PATCH 049/114] fix reference issues --- R/utils-cache.R | 8 ++++---- man/is_cached.Rd | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/utils-cache.R b/R/utils-cache.R index 98d4e7ae0..0635cf73a 100644 --- a/R/utils-cache.R +++ b/R/utils-cache.R @@ -24,7 +24,7 @@ hash_standardize <- function(text) { is_cached <- function(text, transformers, more_specs, - cache_dir = cache_dir()) { + cache_dir = get_cache_dir()) { R.cache::generateCache( key = cache_make_key(text, transformers, more_specs), dirs = cache_dir @@ -111,7 +111,7 @@ cache_make_key <- function(text, transformers, more_specs) { #' @keywords internal cache_find_path <- function(cache_name = NULL) { cache_name <- cache_get_or_derive_name(cache_name) - R.cache::getCachePath(cache_dir(cache_name)) + R.cache::getCachePath(get_cache_dir(cache_name)) } #' Check if a cache is activated @@ -173,7 +173,7 @@ cache_by_expression <- function(text, cache_write <- function(text, transformers, more_specs) { R.cache::generateCache( key = cache_make_key(text, transformers, more_specs), - dirs = cache_dir() + dirs = get_cache_dir() ) %>% file.create() } @@ -194,7 +194,7 @@ cache_get_or_derive_name <- function(cache_name) { cache_name } -cache_dir <- function(cache_name = cache_get_name()) { +get_cache_dir <- function(cache_name = cache_get_name()) { c(getOption("styler.cache_root", "styler"), cache_name) } diff --git a/man/is_cached.Rd b/man/is_cached.Rd index 33b948f24..868c7c50f 100644 --- a/man/is_cached.Rd +++ b/man/is_cached.Rd @@ -4,7 +4,7 @@ \alias{is_cached} \title{Check if text is cached} \usage{ -is_cached(text, transformers, more_specs, cache_dir = cache_dir()) +is_cached(text, transformers, more_specs, cache_dir = get_cache_dir()) } \arguments{ \item{text, transformers, more_specs}{Passed to \code{\link[=cache_make_key]{cache_make_key()}} to generate From 678c528d77a7d477815e5404e3c8f84daed60ea7 Mon Sep 17 00:00:00 2001 From: bersbersbers <12128514+bersbersbers@users.noreply.github.com> Date: Thu, 21 Oct 2021 15:36:57 +0200 Subject: [PATCH 050/114] Fix incorrect option name file_type (close #854) --- R/ui-styling.R | 2 +- man/style_dir.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/ui-styling.R b/R/ui-styling.R index 5e4a88d1d..9117fa3f0 100644 --- a/R/ui-styling.R +++ b/R/ui-styling.R @@ -229,7 +229,7 @@ style_text <- function(text, #' @family stylers #' @examples #' \dontrun{ -#' style_dir("path/to/dir", file_type = c("rmd", ".R")) +#' style_dir("path/to/dir", filetype = c("rmd", ".R")) #' #' # the following is identical (because of ... and defaults) #' # but the first is most convenient: diff --git a/man/style_dir.Rd b/man/style_dir.Rd index da4060a82..1ce1c6310 100644 --- a/man/style_dir.Rd +++ b/man/style_dir.Rd @@ -110,7 +110,7 @@ See section 'Warning' for a good strategy to apply styling safely. \examples{ \dontrun{ -style_dir("path/to/dir", file_type = c("rmd", ".R")) +style_dir("path/to/dir", filetype = c("rmd", ".R")) # the following is identical (because of ... and defaults) # but the first is most convenient: From cf9bb4a12e5706581432ad1f85c1ae72f2b50b3a Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 21 Oct 2021 16:24:58 +0200 Subject: [PATCH 051/114] Add news --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 3d6b665d4..2c4b8436f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,7 +3,7 @@ * Alignment detection respects stylerignore (#850). * Add vignette on distributing style guide (#846). * Enable pre-commit.ci (#843). - +* Fix argument name `filetype` in Example for `style_dir()` (#855). # styler 1.6.2 From d863205c1a1bbc13cb31485d226cddccdd8091e5 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 22 Oct 2021 15:02:42 +0200 Subject: [PATCH 052/114] update GHA - also test on windows-devel (#847) - delete empty workflow file --- .github/workflows/R-CMD-check.yaml | 5 +++-- .github/workflows/check-full.yaml | 0 2 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 .github/workflows/check-full.yaml diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 0d80e6962..74b28bdd7 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -27,9 +27,10 @@ jobs: matrix: config: - {os: macOS-latest, r: 'release'} + - {os: windows-latest, r: 'devel'} - {os: windows-latest, r: 'release'} - - {os: windows-latest, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/latest"} - - {os: ubuntu-18.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest", http-user-agent: "R/4.0.0 (ubuntu-18.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" } + - {os: windows-latest, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/latest"} + - {os: ubuntu-18.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest", http-user-agent: "R/4.0.0 (ubuntu-18.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" } - {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} - {os: ubuntu-18.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} - {os: ubuntu-18.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} diff --git a/.github/workflows/check-full.yaml b/.github/workflows/check-full.yaml deleted file mode 100644 index e69de29bb..000000000 From 262b87350519ba79492fce0ffa0d423b0ec808e3 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Thu, 28 Oct 2021 10:09:24 +0200 Subject: [PATCH 053/114] add messages --- R/zzz.R | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index 408ddbe73..427fc0083 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -3,7 +3,7 @@ op <- options() op.styler <- list( styler.addins_style_transformer = "styler::tidyverse_style()", - styler.cache_root = "styler", + styler.cache_root = NULL, styler.cache_name = styler_version, styler.colored_print.vertical = TRUE, styler.ignore_start = "# styler: off", @@ -13,11 +13,34 @@ ) toset <- !(names(op.styler) %in% names(op)) if (any(toset)) options(op.styler[toset]) + ask_to_switch_to_non_default_cache_root() remove_cache_old_versions() remove_old_cache_files() invisible() } + +ask_to_switch_to_non_default_cache_root <- function(ask = interactive()) { + if (ask && runif(1) > 0.9 && is.null(getOption("styler.cache_root"))) { + cli::cli_inform(paste0( + "The R option `styler.cache_root` is not set, which means the cache ", + "will get cleaned up after 6 days (and repeated styling will be slower).", + " To keep cache files longer, set ", + "the option to location within the {{R.cache}} cache where you want to ", + "store the cache, e.g. `\"styler-perm\"`.\n\n", + "options(styler.cache_root = \"styler-perm\")\n\n", + "in your .Rprofile. Note that the cache literally ", + "takes zero space on your disk, only the inode, and you can always ", + "manually clean up with `styler::cache_clear()`, and if you update the ", + "{{styler}} package, the cache is removed in any case. To ignore this ", + "message in the future, set the default explictly to \"styler\" with\n\n", + "options(styler.cache_root = \"styler\")\n\nin your `.Rprofile`. This ", + "message will only be displayed once in a while.\n" + )) + } + options(styler.cache_root = "styler") +} + remove_old_cache_files <- function() { all_cached <- list.files( R.cache::getCachePath(c("styler", styler_version)), From 649686ffae332b32d4f3f5c9be4d99109299ff30 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Thu, 28 Oct 2021 10:30:36 +0200 Subject: [PATCH 054/114] upate main --- .github/workflows/pkgdown.yaml | 2 +- .github/workflows/test-coverage.yaml | 4 ++-- README.Rmd | 2 +- README.md | 2 +- inst/hooks/require-news-update.R | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 8bc92105d..d1a13500f 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -1,6 +1,6 @@ on: push: - branches: master + branches: main name: pkgdown diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 3058d037b..7dabe0282 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -1,10 +1,10 @@ on: push: branches: - - master + - main pull_request: branches: - - master + - main name: test-coverage diff --git a/README.Rmd b/README.Rmd index 8c05c87f6..7f25cb253 100644 --- a/README.Rmd +++ b/README.Rmd @@ -19,7 +19,7 @@ knitr::opts_chunk$set( [![R build status](https://github.com/r-lib/styler/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/styler/actions) [![Life cycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html) -[![codecov test coverage](https://codecov.io/gh/r-lib/styler/branch/master/graph/badge.svg)](https://codecov.io/gh/r-lib/styler) +[![codecov test coverage](https://codecov.io/gh/r-lib/styler/branch/main/graph/badge.svg)](https://codecov.io/gh/r-lib/styler) [![CRAN Status](https://www.r-pkg.org/badges/version/styler)](https://cran.r-project.org/package=styler) diff --git a/README.md b/README.md index f05c722d1..4ad42762a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ status](https://github.com/r-lib/styler/workflows/R-CMD-check/badge.svg)](https: [![Life cycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html) [![codecov test -coverage](https://codecov.io/gh/r-lib/styler/branch/master/graph/badge.svg)](https://codecov.io/gh/r-lib/styler) +coverage](https://codecov.io/gh/r-lib/styler/branch/main/graph/badge.svg)](https://codecov.io/gh/r-lib/styler) [![CRAN Status](https://www.r-pkg.org/badges/version/styler)](https://cran.r-project.org/package=styler) diff --git a/inst/hooks/require-news-update.R b/inst/hooks/require-news-update.R index 5fc72578d..05d8c950c 100755 --- a/inst/hooks/require-news-update.R +++ b/inst/hooks/require-news-update.R @@ -1,7 +1,7 @@ #! /usr/local/bin/Rscript args <- system2( "git", - c("diff", "upstream/master", "--name-only"), + c("diff", "upstream/main", "--name-only"), stdout = TRUE ) From 6449ca910a632bf4e51808018212478a2f8827b6 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Thu, 28 Oct 2021 10:47:34 +0200 Subject: [PATCH 055/114] add news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 3d6b665d4..08e9aea87 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ * Alignment detection respects stylerignore (#850). * Add vignette on distributing style guide (#846). * Enable pre-commit.ci (#843). +* rename default branch to main (#859). # styler 1.6.2 From f447c1ee2463d86c69cea1076161da3f79aced21 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Thu, 28 Oct 2021 19:55:56 +0200 Subject: [PATCH 056/114] Don't allow multiple since regex is already enough flexible --- DESCRIPTION | 2 +- NEWS.md | 18 ++++++++-- R/nest.R | 18 ++++------ R/stylerignore.R | 11 ++++-- R/zzz.R | 4 +-- man/stylerignore.Rd | 20 ++++------- tests/testthat/test-stylerignore.R | 58 ++++++++---------------------- 7 files changed, 54 insertions(+), 77 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f9db73dbf..5e1cd3751 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,7 +46,7 @@ VignetteBuilder: Encoding: UTF-8 Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "collate", "pkgapi::api_roclet")) -RoxygenNote: 7.1.1.9001 +RoxygenNote: 7.1.2 Collate: 'addins.R' 'communicate.R' diff --git a/NEWS.md b/NEWS.md index 9e3cb38fa..c87e852d3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,21 @@ # styler 1.6.2.9000 (Development version) -* multiple stylerignore patterns can be specified at once and lintr markers - `# nolint`, `# nolint start` and `# nolint end` are now by default recognized - in addition to `# styler: off` and `# styler: on` (#849). +* stylerignore markers are now interpreted as regular expressions instead of + comments that must match exactly. This allows to specify multiple markers in + one regular expression for `styler.ignore_start` and `styler.ignore_stop`, + e.g. to use markers for lintr and styler on the same line, you can use + `options(styler.ignore_start = "nolint start|styler: off"`: + + ```r + # nolint start, styler: off + 1 +1 + # nolint end + # styler: on + ``` + As a consequence of this approach, the defaults for `styler.ignore_start` and + `styler.ignore_stop` omit the `#` (#849). + # styler 1.6.2 diff --git a/R/nest.R b/R/nest.R index 071175b9a..12aadfc90 100644 --- a/R/nest.R +++ b/R/nest.R @@ -162,23 +162,17 @@ find_pos_id_to_keep <- function(pd) { #' Styling is on for all lines by default when you run styler. #' #' - To mark the start of a sequence where you want to turn styling off, use -#' `# styler: off`. For styler version > 1.6.2, `# nolint` and `#nolint start` -#' also works by default. +#' `# styler: off`. #' - To mark the end of this sequence, put `# styler: on` in your code. After -#' that line, styler will again format your code. For styler version > 1.6.2, -#' `#nolint end` also works by default. +#' that line, styler will again format your code. #' - To ignore an inline statement (i.e. just one line), place `# styler: off` -#' at the end of the line. Note that inline statements cannot contain other -#' comments apart from the marker, i.e. a line like -#' `1 # comment # styler: off` won't be ignored. For styler version > 1.6.2, -#' `# nolint` and `#nolint start` also works. -#' +#' at the end of the line. #' To use something else as start and stop markers, set the R options #' `styler.ignore_start` and #' `styler.ignore_stop` using [options()]. For styler version > 1.6.2, the -#' option supports character vectors longer than one. If you want these -#' settings to persist over multiple R sessions, consider setting them in your -#' R profile, e.g. with `usethis::edit_rprofile()`. +#' option supports character vectors longer than one and the marker are not +#' exactly matched, but using a regular expression, which means you can have +#' multiple marker on one line, e.g. `# nolint start styler: off`. #' @name stylerignore #' @examples #' # as long as the order of the markers is correct, the lines are ignored. diff --git a/R/stylerignore.R b/R/stylerignore.R index 2a4995d54..246f83002 100644 --- a/R/stylerignore.R +++ b/R/stylerignore.R @@ -54,7 +54,9 @@ env_add_stylerignore <- function(pd_flat) { #' @keywords internal add_stylerignore <- function(pd_flat) { parse_text <- trimws(pd_flat$text) - start_candidate <- parse_text %in% option_read("styler.ignore_start") + start_candidate <- grepl( + option_read("styler.ignore_start"), parse_text + ) & pd_flat$token == "COMMENT" pd_flat$stylerignore <- rep(FALSE, length(start_candidate)) env_current$any_stylerignore <- any(start_candidate) if (!env_current$any_stylerignore) { @@ -64,7 +66,10 @@ add_stylerignore <- function(pd_flat) { pd_flat_lat_line1 <- lag(pd_flat$line2, default = 0) on_same_line <- pd_flat$line1 == pd_flat_lat_line1 cumsum_start <- cumsum(start_candidate & !on_same_line) - cumsum_stop <- cumsum(parse_text %in% option_read("styler.ignore_stop")) + cumsum_stop <- cumsum( + grepl(option_read("styler.ignore_stop"), parse_text) & + pd_flat$token == "COMMENT" + ) pd_flat$indicator_off <- cumsum_start + cumsum_stop is_invalid <- cumsum_start - cumsum_stop < 0 | cumsum_start - cumsum_stop > 1 if (any(is_invalid)) { @@ -105,7 +110,7 @@ apply_stylerignore <- function(flattened_pd) { colnames_required_apply_stylerignore <- c( "pos_id_", "lag_newlines", "lag_spaces", "text", "first_pos_id_in_segment" ) - # cannot rely on flattened_pd$text %in% option_read("styler.ignore_start") + # cannot rely on flattened_pd$text == option_read("styler.ignore_start") # because if the marker logic is not correct (twice off in a row), we'll # get it wrong. to_ignore <- flattened_pd$stylerignore == TRUE diff --git a/R/zzz.R b/R/zzz.R index e91d64956..5646ca9da 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -5,8 +5,8 @@ styler.addins_style_transformer = "styler::tidyverse_style()", styler.cache_name = styler_version, styler.colored_print.vertical = TRUE, - styler.ignore_start = c("# styler: off", "# nolint", "nolint start"), - styler.ignore_stop = c("# styler: on", "# nolint end"), + styler.ignore_start = "styler: off", + styler.ignore_stop = "styler: on", styler.quiet = FALSE, styler.test_dir_writable = TRUE ) diff --git a/man/stylerignore.Rd b/man/stylerignore.Rd index e1362b577..f43563654 100644 --- a/man/stylerignore.Rd +++ b/man/stylerignore.Rd @@ -13,24 +13,18 @@ making stylerignore redundant. See a few illustrative examples below. Styling is on for all lines by default when you run styler. \itemize{ \item To mark the start of a sequence where you want to turn styling off, use -\verb{# styler: off}. For styler version > 1.6.2, \verb{# nolint} and \verb{#nolint start} -also works by default. +\verb{# styler: off}. \item To mark the end of this sequence, put \verb{# styler: on} in your code. After -that line, styler will again format your code. For styler version > 1.6.2, -\verb{#nolint end} also works by default. +that line, styler will again format your code. \item To ignore an inline statement (i.e. just one line), place \verb{# styler: off} -at the end of the line. Note that inline statements cannot contain other -comments apart from the marker, i.e. a line like -\code{1 # comment # styler: off} won't be ignored. For styler version > 1.6.2, -\verb{# nolint} and \verb{#nolint start} also works. -} - +at the end of the line. To use something else as start and stop markers, set the R options \code{styler.ignore_start} and \code{styler.ignore_stop} using \code{\link[=options]{options()}}. For styler version > 1.6.2, the -option supports character vectors longer than one. If you want these -settings to persist over multiple R sessions, consider setting them in your -R profile, e.g. with \code{usethis::edit_rprofile()}. +option supports character vectors longer than one and the marker are not +exactly matched, but using a regular expression, which means you can have +multiple marker on one line, e.g. \verb{# nolint start styler: off}. +} } \examples{ # as long as the order of the markers is correct, the lines are ignored. diff --git a/tests/testthat/test-stylerignore.R b/tests/testthat/test-stylerignore.R index 708b77f17..f089eb84e 100644 --- a/tests/testthat/test-stylerignore.R +++ b/tests/testthat/test-stylerignore.R @@ -77,49 +77,6 @@ test_that("works with other markers", { ) }) -test_that("works with multiple markers", { - expect_equal( - withr::with_options( - list( - styler.ignore_start = c("# startignore", "#lintstart"), - styler.ignore_stop = "# xxx" - ), - { - style_text(c( - "1+1", - "#lintstart", - "1+1", - "# xxx", - "1+1" - )) %>% - as.character() - } - ), - c("1 + 1", "#lintstart", "1+1", "# xxx", "1 + 1") - ) -}) - -test_that("works with multiple markers", { - expect_equal( - withr::with_options( - list( - styler.ignore_start = "# startignore", - styler.ignore_stop = c("# xxx", "# lintstop") - ), - { - style_text(c( - "1+1", - "# startignore", - "1+1", - "# lintstop", - "1+1" - )) %>% - as.character() - } - ), - c("1 + 1", "# startignore", "1+1", "# lintstop", "1 + 1") - ) -}) test_that("works for multiple markers inline", { withr::local_options(styler.ignore_start = "# noeq", ) @@ -134,6 +91,21 @@ test_that("works for multiple markers inline", { ) }) + +test_that("works for multiple markers inline on one line", { + withr::local_options(styler.ignore_start = "nolint start|styler: off") + expect_equal( + style_text(c( + "1+1", + "1+1# nolint start styler: off", + "1+1" + )) %>% + as.character(), + c("1 + 1", "1+1# nolint start styler: off", "1 + 1") + ) +}) + + test_that("works with other markers", { expect_warning( withr::with_options( From eaf2864d67b7f61c80c1ca35c47722786b13795b Mon Sep 17 00:00:00 2001 From: Lorenz Date: Thu, 28 Oct 2021 23:15:25 +0200 Subject: [PATCH 057/114] bump From 48436d8c79234a7976e3118b57fd347aa4f4a7de Mon Sep 17 00:00:00 2001 From: Lorenz Date: Thu, 28 Oct 2021 23:16:03 +0200 Subject: [PATCH 058/114] bump From 77b96ed150ca0db2d1406427d8d28a85ba17548c Mon Sep 17 00:00:00 2001 From: Lorenz Date: Fri, 29 Oct 2021 14:06:13 +0200 Subject: [PATCH 059/114] link GitHub template --- NEWS.md | 2 +- inst/WORDLIST | 5 +++++ vignettes/distribute_custom_style_guides.Rmd | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 01ef4ddfa..b6e189fa9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ # styler 1.6.2.9000 (Development version) * Alignment detection respects stylerignore (#850). -* Add vignette on distributing style guide (#846). +* Add vignette on distributing style guide (#846, #861). * Enable pre-commit.ci (#843). * rename default branch to main (#859). * Fix argument name `filetype` in Example for `style_dir()` (#855). diff --git a/inst/WORDLIST b/inst/WORDLIST index 1c5fc055b..293a406ac 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -64,6 +64,7 @@ filetype forcond formatter funct +gadenbuie gcc getChecksum getOption @@ -71,6 +72,7 @@ getRversion ggplot github gitsum +grkstyle GSOC hashFiles helpfiles @@ -173,6 +175,7 @@ roclet roclets rootPath ROOTPATH +ropensci roundtrip roxgen roxygen @@ -193,6 +196,7 @@ rstudioapi saamwerk saveRDS seealso +semicoloner sep sessioninfo setCacheRootPath @@ -203,6 +207,7 @@ shinymeta shinyMonacoEditor shinyobjects ShinyQuickStarter +spaceout sprintf stackoverflow StackOverflow diff --git a/vignettes/distribute_custom_style_guides.Rmd b/vignettes/distribute_custom_style_guides.Rmd index 164eba803..352262c13 100644 --- a/vignettes/distribute_custom_style_guides.Rmd +++ b/vignettes/distribute_custom_style_guides.Rmd @@ -20,11 +20,25 @@ style guide with `create_style_guide()`. ## Reference implementations -There are two packages that implement a third-party style guide: +There are a few packages that implement a third-party style guide that are +maintained by styler contributors: +* [lorenzwalthert/semicoloner](https://github.com/lorenzwalthert/semicoloner) * [lorenzwalthert/oneliner](https://github.com/lorenzwalthert/oneliner) * [mlr-org/styler.mlr](https://github.com/mlr-org/styler.mlr) +Other available style guides include: + +* [ropensci-review-tools/spaceout](https://github.com/ropensci-review-tools/spaceout) +* [gadenbuie/grkstyle](https://github.com/gadenbuie/grkstyle) + +You made one too? Please submit a PR to include it in the list. + +To start out, you can use the +[GitHub Template](https://github.com/lorenzwalthert/styler.yours) for +third-party style guides that has already the right directory structure and +patterns described below in place. + ## Design patterns The style guides mentioned above follow best practices and can serve as a good From 416b41aa3005ade85cc2bb94c691e0b885ff11e2 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Fri, 29 Oct 2021 15:22:28 +0200 Subject: [PATCH 060/114] reverse order --- vignettes/distribute_custom_style_guides.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vignettes/distribute_custom_style_guides.Rmd b/vignettes/distribute_custom_style_guides.Rmd index 352262c13..94a4eaaec 100644 --- a/vignettes/distribute_custom_style_guides.Rmd +++ b/vignettes/distribute_custom_style_guides.Rmd @@ -32,13 +32,13 @@ Other available style guides include: * [ropensci-review-tools/spaceout](https://github.com/ropensci-review-tools/spaceout) * [gadenbuie/grkstyle](https://github.com/gadenbuie/grkstyle) -You made one too? Please submit a PR to include it in the list. - To start out, you can use the [GitHub Template](https://github.com/lorenzwalthert/styler.yours) for third-party style guides that has already the right directory structure and patterns described below in place. +You made one too? Please submit a PR to include it in the list. + ## Design patterns The style guides mentioned above follow best practices and can serve as a good From 6ed406ba86228b5e8c0fef81521f0e822671c92a Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Tue, 9 Nov 2021 20:23:02 +0100 Subject: [PATCH 061/114] update pre-commit --- .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 2735cfe77..fc6cea03c 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.9127 + rev: v0.1.3.9135 hooks: - id: style-files args: [--style_pkg=styler, --style_fun=tidyverse_style] From d73c393a403618cdc6d53ebbda7e5681c4ce57d1 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Wed, 17 Nov 2021 22:51:43 +0100 Subject: [PATCH 062/114] bump to 3.4 and remove backports --- DESCRIPTION | 3 ++- R/zzz.R | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5e1cd3751..70101c93f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,8 +16,9 @@ Description: Pretty-prints R code without changing the user's formatting License: MIT + file LICENSE URL: https://github.com/r-lib/styler, https://styler.r-lib.org BugReports: https://github.com/r-lib/styler/issues +Depends: + R (>= 3.4.0) Imports: - backports (>= 1.1.0), cli (>= 1.1.0), glue, magrittr (>= 2.0.0), diff --git a/R/zzz.R b/R/zzz.R index 427fc0083..44534799e 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,5 +1,4 @@ .onLoad <- function(libname, pkgname) { - backports::import(pkgname, "trimws") op <- options() op.styler <- list( styler.addins_style_transformer = "styler::tidyverse_style()", From 2e840533fdc7d3ee00ff8f67c31724de938756f6 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Wed, 17 Nov 2021 22:52:40 +0100 Subject: [PATCH 063/114] remove < 3.4 related problem --- NEWS.md | 2 ++ R/parse.R | 25 ------------------------- R/transform-files.R | 2 +- man/ensure_valid_pd.Rd | 17 ----------------- tests/testthat/test-parsing.R | 15 --------------- 5 files changed, 3 insertions(+), 58 deletions(-) delete mode 100644 man/ensure_valid_pd.Rd diff --git a/NEWS.md b/NEWS.md index ea1b17161..21dbc4c96 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,8 @@ (also used by {precommit}). * rename default branch to main (#859). * Fix argument name `filetype` in Example for `style_dir()` (#855). +* Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which + allowed to remove the dependency at {backports} and some exception handling. # styler 1.6.2 diff --git a/R/parse.R b/R/parse.R index 13a4788e6..a82c60637 100644 --- a/R/parse.R +++ b/R/parse.R @@ -127,7 +127,6 @@ add_id_and_short <- function(pd) { #' @importFrom magrittr or #' @keywords internal ensure_correct_txt <- function(pd, text) { - ensure_valid_pd(pd) is_problematic_text <- or( is_insufficiently_parsed_string(pd), is_insufficiently_parsed_number(pd) @@ -173,30 +172,6 @@ ensure_correct_txt <- function(pd, text) { arrange_pos_id() } -#' Ensure that the parse data is valid -#' -#' Test whether all non-terminals have at least one child and throw an error -#' otherwise. As this is check is rather expensive, it is only -#' carried out for configurations we have good reasons to expect problems. -#' @param pd A parse table. -#' @importFrom rlang abort -#' @keywords internal -ensure_valid_pd <- function(pd) { - if (getRversion() < "3.2") { - non_terminals <- pd %>% - filter(terminal == FALSE) - valid_pd <- non_terminals$id %>% - map_lgl(~ .x %in% pd$parent) %>% - all() - if (!valid_pd) { - abort(paste( - "The parse data is not valid and the problem is most likely related", - "to the parser in base R. Please install R >= 3.2 and try again." - )) - } - } - TRUE -} #' Identify strings that were not fully parsed #' diff --git a/R/transform-files.R b/R/transform-files.R index b8cf90f0c..619b134e5 100644 --- a/R/transform-files.R +++ b/R/transform-files.R @@ -232,7 +232,7 @@ parse_transform_serialize_r <- function(text, return("") } transformers <- transformers_drop( - if (getRversion() < 3.4) text else pd_nested$text[!pd_nested$is_cached], + pd_nested$text[!pd_nested$is_cached], transformers ) diff --git a/man/ensure_valid_pd.Rd b/man/ensure_valid_pd.Rd deleted file mode 100644 index c6e1cd8d9..000000000 --- a/man/ensure_valid_pd.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/parse.R -\name{ensure_valid_pd} -\alias{ensure_valid_pd} -\title{Ensure that the parse data is valid} -\usage{ -ensure_valid_pd(pd) -} -\arguments{ -\item{pd}{A parse table.} -} -\description{ -Test whether all non-terminals have at least one child and throw an error -otherwise. As this is check is rather expensive, it is only -carried out for configurations we have good reasons to expect problems. -} -\keyword{internal} diff --git a/tests/testthat/test-parsing.R b/tests/testthat/test-parsing.R index 08d3d410b..df460975c 100644 --- a/tests/testthat/test-parsing.R +++ b/tests/testthat/test-parsing.R @@ -28,8 +28,6 @@ test_that("repreated parsing solves wrong parent assignment", { }) test_that("long strings are parsed correctly", { - if (getRversion() < "3.2") skip("skip on R < 3.2 because of parsing problems") - expect_warning( test_collection("parsing", "long_strings", transformer = style_text), NA @@ -47,20 +45,7 @@ test_that("0x number representation is preserved with(out) L", { }) -test_that("issues with parsing long strings on R 3.1 can be detected", { - if (getRversion() >= "3.2") { - skip("skip on R >= 3.2 because parsing probmes don't appear") - } - expect_error( - test_collection("parsing", "long_strings", transformer = style_text), - "install R .* 3.2" - ) -}) - - test_that("CRLF EOLs fail with informative error", { - skip_if(getRversion() < "3.4") - expect_error( style_text("glück <- 3\r\n glück + 1"), "Please change the EOL character in your editor to Unix style and try again." From 12ad8e5778a8dcc48fb5fc6b559efa897d294bda Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 20 Nov 2021 23:04:36 +0100 Subject: [PATCH 064/114] use drop-in replacement for xfun::read_utf8() --- R/roxygen-examples-find.R | 2 +- R/testing.R | 2 +- R/ui-styling.R | 4 ++-- man/style_file.Rd | 4 ++-- tests/testthat/test-parsing.R | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/roxygen-examples-find.R b/R/roxygen-examples-find.R index 6b0be661e..941414b14 100644 --- a/R/roxygen-examples-find.R +++ b/R/roxygen-examples-find.R @@ -22,7 +22,7 @@ identify_start_to_stop_of_roxygen_examples_from_text <- function(text) { } identify_start_to_stop_of_roxygen_examples <- function(path) { - content <- xfun::read_utf8(path) + content <- read_utf8_bare(path) identify_start_to_stop_of_roxygen_examples_from_text(content) } diff --git a/R/testing.R b/R/testing.R index 9754b9a16..1238b8e6f 100644 --- a/R/testing.R +++ b/R/testing.R @@ -110,7 +110,7 @@ transform_and_check <- function(in_item, out_item, write_tree = NA, out_tree = "_tree", ...) { write_tree <- set_arg_write_tree(write_tree) - read_in <- xfun::read_utf8(in_item) + read_in <- read_utf8_bare(in_item) if (write_tree) { create_tree(read_in) %>% write.table(out_tree, diff --git a/R/ui-styling.R b/R/ui-styling.R index 9117fa3f0..bd035c336 100644 --- a/R/ui-styling.R +++ b/R/ui-styling.R @@ -312,7 +312,7 @@ prettify_any <- function(transformers, #' @inheritSection style_pkg Round trip validation #' @examples #' file <- tempfile("styler", fileext = ".R") -#' xfun::write_utf8("1++1", file) +#' writeLines("1++1", file) #' #' # the following is identical (because of ... and defaults), #' # but the first is most convenient: @@ -325,7 +325,7 @@ prettify_any <- function(transformers, #' # name levels explicitly to not style less invasive levels #' style_file(file, scope = I(c("tokens", "spaces")), strict = TRUE) #' -#' xfun::read_utf8(file) +#' readLines(file) #' unlink(file) #' @family stylers #' @export diff --git a/man/style_file.Rd b/man/style_file.Rd index 3c58e917f..95fec034e 100644 --- a/man/style_file.Rd +++ b/man/style_file.Rd @@ -97,7 +97,7 @@ See section 'Warning' for a good strategy to apply styling safely. \examples{ file <- tempfile("styler", fileext = ".R") -xfun::write_utf8("1++1", file) +writeLines("1++1", file) # the following is identical (because of ... and defaults), # but the first is most convenient: @@ -110,7 +110,7 @@ style_file(file, scope = "indention", strict = TRUE) # name levels explicitly to not style less invasive levels style_file(file, scope = I(c("tokens", "spaces")), strict = TRUE) -xfun::read_utf8(file) +readLines(file) unlink(file) } \seealso{ diff --git a/tests/testthat/test-parsing.R b/tests/testthat/test-parsing.R index df460975c..73d0db1cf 100644 --- a/tests/testthat/test-parsing.R +++ b/tests/testthat/test-parsing.R @@ -21,8 +21,8 @@ test_that("repreated parsing solves wrong parent assignment", { "R -q -e \"styler::cache_deactivate(); styler::style_file(\\\"", path_temp, "\\\")\"" ) calls_sys(sys_call, intern = FALSE, ignore.stdout = TRUE, ignore.stderr = TRUE) - ref <- xfun::read_utf8(testthat_file("parsing", "repeated_parsing-out.R")) - result <- xfun::read_utf8(path_temp) + ref <- read_utf8_bare(testthat_file("parsing", "repeated_parsing-out.R")) + result <- read_utf8_bare(path_temp) expect_equal(ref, result) unlink(dir) }) From 3114e9417fe94ba24ef0af5f3fc14857bb7f691d Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 20 Nov 2021 23:20:23 +0100 Subject: [PATCH 065/114] complete / improve on #853 --- R/zzz.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index 44534799e..1464cd2dd 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -36,8 +36,8 @@ ask_to_switch_to_non_default_cache_root <- function(ask = interactive()) { "options(styler.cache_root = \"styler\")\n\nin your `.Rprofile`. This ", "message will only be displayed once in a while.\n" )) + options(styler.cache_root = "styler") } - options(styler.cache_root = "styler") } remove_old_cache_files <- function() { From de0091afdbb2c3e22bfeadb27b856ea991a30dce Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 20 Nov 2021 23:24:21 +0100 Subject: [PATCH 066/114] remove xfun dep --- DESCRIPTION | 1 - NEWS.md | 1 + R/io.R | 9 ++++++++- man/write_utf8.Rd | 12 ++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 man/write_utf8.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 70101c93f..4aa682d9f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,7 +30,6 @@ Imports: tibble (>= 1.4.2), tools, withr (>= 1.0.0), - xfun (>= 0.1) Suggests: data.tree (>= 0.1.6), digest, diff --git a/NEWS.md b/NEWS.md index 21dbc4c96..ef6ebddb9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,7 @@ * Fix argument name `filetype` in Example for `style_dir()` (#855). * Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which allowed to remove the dependency at {backports} and some exception handling. +* Remove dependency on {xfun} (#866). # styler 1.6.2 diff --git a/R/io.R b/R/io.R index 9caad1a67..0c588500e 100644 --- a/R/io.R +++ b/R/io.R @@ -42,7 +42,7 @@ transform_utf8_one <- function(path, fun, dry) { } else if (dry == "on") { # don't do anything } else if (dry == "off") { - xfun::write_utf8(new, path) + write_utf8(new, path) } else { # not implemented } @@ -114,3 +114,10 @@ read_utf8_bare <- function(con, warn = TRUE) { invalid_utf8 <- function(x) { which(!is.na(x) & is.na(iconv(x, "UTF-8", "UTF-8"))) } + +#' Drop-in replacement for `xfun::write_utf8()` +#' @keywords internal +write_utf8 <- function(text, con, ...) { + withr::local_options(encoding = "native.enc") + writeLines(enc2utf8(text), con, ..., useBytes = TRUE) +} diff --git a/man/write_utf8.Rd b/man/write_utf8.Rd new file mode 100644 index 000000000..9955e86e2 --- /dev/null +++ b/man/write_utf8.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/io.R +\name{write_utf8} +\alias{write_utf8} +\title{Drop-in replacement for \code{xfun::write_utf8()}} +\usage{ +write_utf8(text, con, ...) +} +\description{ +Drop-in replacement for \code{xfun::write_utf8()} +} +\keyword{internal} From e573d1dff1c115bc1ec75cd6437573c0bc15081e Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 21 Nov 2021 11:23:31 +0100 Subject: [PATCH 067/114] use touchstone bleeding edge --- .github/workflows/touchstone-receive.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/touchstone-receive.yaml b/.github/workflows/touchstone-receive.yaml index 085efd749..589272869 100644 --- a/.github/workflows/touchstone-receive.yaml +++ b/.github/workflows/touchstone-receive.yaml @@ -72,7 +72,7 @@ jobs: - name: Install dependencies run: | remotes::install_deps(dependencies = TRUE) - remotes::install_github("lorenzwalthert/touchstone") + remotes::install_github("lorenzwalthert/touchstone@verbose-error-on-pkg-install") remotes::install_cran(c('ggplot2', 'dplyr')) pkg <- basename(getwd()) if (pkg %in% rownames(installed.packages())) { From 8feabfcd49decb2a35df3f0cfccaa76d5079af6b Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 21 Nov 2021 17:14:51 +0100 Subject: [PATCH 068/114] bump From 73a041366040e8c5ee9ed8d86a5548efda7b5d01 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 21 Nov 2021 18:17:33 +0100 Subject: [PATCH 069/114] Revert "use touchstone bleeding edge" This reverts commit e573d1dff1c115bc1ec75cd6437573c0bc15081e. --- .github/workflows/touchstone-receive.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/touchstone-receive.yaml b/.github/workflows/touchstone-receive.yaml index 589272869..085efd749 100644 --- a/.github/workflows/touchstone-receive.yaml +++ b/.github/workflows/touchstone-receive.yaml @@ -72,7 +72,7 @@ jobs: - name: Install dependencies run: | remotes::install_deps(dependencies = TRUE) - remotes::install_github("lorenzwalthert/touchstone@verbose-error-on-pkg-install") + remotes::install_github("lorenzwalthert/touchstone") remotes::install_cran(c('ggplot2', 'dplyr')) pkg <- basename(getwd()) if (pkg %in% rownames(installed.packages())) { From 6e6272c9fd3247533e12e99fbdbbfbac8641cc3c Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 28 Nov 2021 19:31:47 +0100 Subject: [PATCH 070/114] make no trailing line a pre-processing step like trimming whitespaces --- NEWS.md | 1 + R/transform-files.R | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index ef6ebddb9..836a8ece9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,7 @@ (also used by {precommit}). * rename default branch to main (#859). * Fix argument name `filetype` in Example for `style_dir()` (#855). +* ensure a trailing blank line also if the input is cached (#867). * Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which allowed to remove the dependency at {backports} and some exception handling. * Remove dependency on {xfun} (#866). diff --git a/R/transform-files.R b/R/transform-files.R index 619b134e5..6a5d29c06 100644 --- a/R/transform-files.R +++ b/R/transform-files.R @@ -88,7 +88,7 @@ make_transformer <- function(transformers, assert_transformers(transformers) function(text) { - text <- trimws(text, which = "right") + text <- ensure_last_n_empty(trimws(text, which = "right"), n = 0L) should_use_cache <- cache_is_activated() if (should_use_cache) { From 9803e556d1d62aab197268c5260794769e7ed4d7 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 28 Nov 2021 19:52:59 +0100 Subject: [PATCH 071/114] styled text has no trailing, input also not (since last commit) --- R/utils-cache.R | 4 ++-- man/hash_standardize.Rd | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/R/utils-cache.R b/R/utils-cache.R index 0635cf73a..517ddd6c8 100644 --- a/R/utils-cache.R +++ b/R/utils-cache.R @@ -1,13 +1,13 @@ #' Standardize text for hashing #' #' Make sure text after styling results in the same hash as text before styling -#' if it is indeed identical. +#' if it is indeed identical. This function expects trailing blank lines in +#' `text` were removed prior to passing it to this function. #' @param text A character vector. #' @keywords internal hash_standardize <- function(text) { text %>% convert_newlines_to_linebreaks() %>% - ensure_last_n_empty() %>% enc2utf8() %>% paste0(collapse = "\n") %>% list() diff --git a/man/hash_standardize.Rd b/man/hash_standardize.Rd index 8f210cc1e..104b8e85b 100644 --- a/man/hash_standardize.Rd +++ b/man/hash_standardize.Rd @@ -11,6 +11,7 @@ hash_standardize(text) } \description{ Make sure text after styling results in the same hash as text before styling -if it is indeed identical. +if it is indeed identical. This function expects trailing blank lines in +\code{text} were removed prior to passing it to this function. } \keyword{internal} From b5e86ffb7624c7e1ea729504b3529de2c32eada7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Nov 2021 18:57:33 +0000 Subject: [PATCH 072/114] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/lorenzwalthert/precommit: v0.1.3.9135 → v0.1.3.9139](https://github.com/lorenzwalthert/precommit/compare/v0.1.3.9135...v0.1.3.9139) --- .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 fc6cea03c..71bd1be0d 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.9135 + rev: v0.1.3.9139 hooks: - id: style-files args: [--style_pkg=styler, --style_fun=tidyverse_style] From f8cb7335ed5013dc5f972c7bf42f62872bb3ad0e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Nov 2021 19:03:23 +0000 Subject: [PATCH 073/114] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- R/rules-line-breaks.R | 3 ++- man/rds_to_version.Rd | 2 +- man/set_line_break_before_curly_opening.Rd | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index eb93240e4..3212ee46f 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -41,7 +41,8 @@ #' # brace expressions go on new line if part of a pipe, in function call... #' c( #' data %>% -#' filter(bar) %>% { +#' filter(bar) %>% +#' { #' cor(.$col1, .$col2, use = "complete.obs") #' } #' ) diff --git a/man/rds_to_version.Rd b/man/rds_to_version.Rd index 59d9d15b7..5a4b236a4 100644 --- a/man/rds_to_version.Rd +++ b/man/rds_to_version.Rd @@ -12,6 +12,6 @@ rds_to_version(path, version = 2) \item{version}{The target version.} } \description{ -Needed to make \code{\link[testthat:expect_known_output]{testthat::expect_known_value()}} work on R < 3.6. +Needed to make \code{\link[testthat:expect_known_value]{testthat::expect_known_value()}} work on R < 3.6. } \keyword{internal} diff --git a/man/set_line_break_before_curly_opening.Rd b/man/set_line_break_before_curly_opening.Rd index bae84e953..f2f2efd9a 100644 --- a/man/set_line_break_before_curly_opening.Rd +++ b/man/set_line_break_before_curly_opening.Rd @@ -50,7 +50,8 @@ tryGugus( # brace expressions go on new line if part of a pipe, in function call... c( data \%>\% - filter(bar) \%>\% { + filter(bar) \%>\% + { cor(.$col1, .$col2, use = "complete.obs") } ) From d6675bbbaf3e16fa626101df58c60728a3ab9178 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 21 Nov 2021 17:14:51 +0100 Subject: [PATCH 074/114] bump From 5f576062763ccd0097000d1756edab2ee0ca8998 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Wed, 8 Dec 2021 17:12:58 +0100 Subject: [PATCH 075/114] use boostrap 5 --- _pkgdown.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/_pkgdown.yml b/_pkgdown.yml index 0857dd929..c36cc1472 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -41,6 +41,8 @@ template: docsearch: api_key: 13580d327d8a7159f83a7cff178d2141 index_name: r-lib_styler + bootstrap: 5 + authors: Kirill Müller: From b9428f5bdc706ff943db637a0ce207a82913311f Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Wed, 8 Dec 2021 17:32:12 +0100 Subject: [PATCH 076/114] use touchstone after api change --- touchstone/script.R | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/touchstone/script.R b/touchstone/script.R index 9d2a1e1d0..6b89d3eb0 100644 --- a/touchstone/script.R +++ b/touchstone/script.R @@ -1,18 +1,18 @@ library(touchstone) -refs_install() +branch_install() -clear_ref_caches <- function() { - purrr::walk(c(ref_get_or_fail("GITHUB_BASE_REF"), ref_get_or_fail("GITHUB_HEAD_REF")), +clear_branch_caches <- function() { + purrr::walk(c(branch_get_or_fail("GITHUB_BASE_REF"), branch_get_or_fail("GITHUB_HEAD_REF")), styler::cache_clear, ask = FALSE ) } -clear_ref_caches() +clear_branch_caches() -benchmark_run_ref( +benchmark_run( expr_before_benchmark = { library(styler) cache_deactivate() @@ -22,7 +22,7 @@ benchmark_run_ref( ) clear_ref_caches() -benchmark_run_ref( +benchmark_run( expr_before_benchmark = { library(styler) cache_activate(gert::git_branch()) @@ -31,8 +31,9 @@ benchmark_run_ref( n = 30 ) -clear_ref_caches() -benchmark_run_ref( +clear_branch_caches() + +benchmark_run( expr_before_benchmark = { library(styler) cache_activate(gert::git_branch()) @@ -44,6 +45,6 @@ benchmark_run_ref( n = 30 ) -clear_ref_caches() +clear_branch_caches() benchmarks_analyze() From 63ef1d7babafc1beae909e08ab81fd4591aebe5e Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Wed, 8 Dec 2021 17:44:42 +0100 Subject: [PATCH 077/114] news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 836a8ece9..cc3809be8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,7 @@ * Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which allowed to remove the dependency at {backports} and some exception handling. * Remove dependency on {xfun} (#866). +* use bootstrap 5 with {pkgdown} 2.0 # styler 1.6.2 From 7042b12140f6cc4c00f9aef97e079d6233d7c48c Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Wed, 8 Dec 2021 18:36:20 +0100 Subject: [PATCH 078/114] fix issue --- touchstone/script.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/touchstone/script.R b/touchstone/script.R index 6b89d3eb0..1bbcec1df 100644 --- a/touchstone/script.R +++ b/touchstone/script.R @@ -21,7 +21,7 @@ benchmark_run( n = 30 ) -clear_ref_caches() +clear_branch_caches() benchmark_run( expr_before_benchmark = { library(styler) @@ -47,4 +47,4 @@ benchmark_run( clear_branch_caches() -benchmarks_analyze() +benchmark_analyze() From 5516800898656c145c41a8ff3e917ac36fdf86c6 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Wed, 8 Dec 2021 22:02:12 +0100 Subject: [PATCH 079/114] remove helper from index --- R/testing.R | 1 + man/local_test_setup.Rd | 1 + 2 files changed, 2 insertions(+) diff --git a/R/testing.R b/R/testing.R index 1238b8e6f..e1de386e8 100644 --- a/R/testing.R +++ b/R/testing.R @@ -337,6 +337,7 @@ activate_testthat_cache <- purrr::partial(cache_activate, "testthat") #' @param .local_envir The environment to use for scoping. #' @details #' * make styler quiet. +#' @keywords internal local_test_setup <- function(cache = FALSE, .local_envir = parent.frame()) { current_cache <- cache_info(format = "tabular") diff --git a/man/local_test_setup.Rd b/man/local_test_setup.Rd index 108b3eb68..ddc76702c 100644 --- a/man/local_test_setup.Rd +++ b/man/local_test_setup.Rd @@ -20,3 +20,4 @@ Establish testing setup for current environment \item make styler quiet. } } +\keyword{internal} From 816a71896218c0481a3122b23eabd150fcec8b9b Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 11 Dec 2021 00:03:09 +0100 Subject: [PATCH 080/114] don't opt in to boostrap 5 --- _pkgdown.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/_pkgdown.yml b/_pkgdown.yml index c36cc1472..080c0ac2f 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -41,7 +41,6 @@ template: docsearch: api_key: 13580d327d8a7159f83a7cff178d2141 index_name: r-lib_styler - bootstrap: 5 authors: From e658d91c14fcc58adc8cd1fd1b6e3317031ce46d Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 11 Dec 2021 11:46:22 +0100 Subject: [PATCH 081/114] add pre-commit via GHA --- .github/workflows/pre-commit.yaml | 55 +++++++++++++++++++++++++++++++ NEWS.md | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pre-commit.yaml diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 000000000..0cdf2e517 --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,55 @@ +name: pre-commit +on: + push: + branches-ignore: + - 'master' + - 'main' + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +jobs: + pre-commit: + runs-on: ubuntu-18.04 + if: >- + !contains(github.event.head_commit.message, 'ci skip') && + ( + startsWith(github.ref, 'refs/heads') || + github.event.pull_request.draft == false + ) + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Install system dependencies + if: runner.os == 'Linux' + run: | + # your system installation code here + # sudo apt-get install -y libcurl4-openssl-dev + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.8" + architecture: "x64" + - name: Run pre-commit + uses: pre-commit/action@v2.0.3 + - name: Commit files + if: failure() && startsWith(github.ref, 'refs/heads') + run: | + if [[ `git status --porcelain --untracked-files=no` ]]; then + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git checkout -- .github/workflows + git commit -m "pre-commit" -a + fi + - name: Push changes + if: failure() && startsWith(github.ref, 'refs/heads') + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} + env: + RENV_CONFIG_CACHE_ENABLED: FALSE diff --git a/NEWS.md b/NEWS.md index cc3809be8..178ea8380 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,7 +13,7 @@ * Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which allowed to remove the dependency at {backports} and some exception handling. * Remove dependency on {xfun} (#866). -* use bootstrap 5 with {pkgdown} 2.0 +* use pre-commit via GitHub Actions (#872). # styler 1.6.2 From c88a2fad692b7544dbb839a22f48a600a0d631ff Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 11 Dec 2021 11:59:50 +0100 Subject: [PATCH 082/114] also run on main --- .github/workflows/pre-commit.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 0cdf2e517..6167957bd 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -1,10 +1,7 @@ name: pre-commit on: - push: - branches-ignore: - - 'master' - - 'main' - pull_request: +- push +- pull_request: types: [opened, synchronize, reopened, ready_for_review] jobs: From a6c0b1b8737b2d5dba8c304a299aa7266abed760 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 11 Dec 2021 12:02:03 +0100 Subject: [PATCH 083/114] add style problem --- R/addins.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/addins.R b/R/addins.R index 5e265b11f..a4f707c17 100644 --- a/R/addins.R +++ b/R/addins.R @@ -46,7 +46,7 @@ NULL #' @importFrom rlang abort #' @keywords internal -style_active_file <- function() { +style_active_file <-function() { communicate_addins_style_transformers() context <- get_rstudio_context() transformer <- make_transformer(get_addins_style_transformer(), From 6c6b2c32880f7113d49ac49b39ab83c052970251 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 11 Dec 2021 12:04:36 +0100 Subject: [PATCH 084/114] also on master and main push --- .github/workflows/pre-commit.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 6167957bd..84bf39c0c 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -1,7 +1,10 @@ name: pre-commit on: -- push -- pull_request: + push: + branches: + - main + - master + pull_request: types: [opened, synchronize, reopened, ready_for_review] jobs: From 2f1a2cc49ce3e4731838945b93e833b842313022 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 11 Dec 2021 11:11:03 +0000 Subject: [PATCH 085/114] pre-commit --- R/addins.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/addins.R b/R/addins.R index a4f707c17..5e265b11f 100644 --- a/R/addins.R +++ b/R/addins.R @@ -46,7 +46,7 @@ NULL #' @importFrom rlang abort #' @keywords internal -style_active_file <-function() { +style_active_file <- function() { communicate_addins_style_transformers() context <- get_rstudio_context() transformer <- make_transformer(get_addins_style_transformer(), From d39832a89d943fa051a2982706ba9df49fdbedb3 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 11 Dec 2021 12:12:29 +0100 Subject: [PATCH 086/114] bump From 1552a6352e1846d07c69497566280e8de48f2c49 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 11 Dec 2021 12:20:23 +0100 Subject: [PATCH 087/114] only push conditional on master --- .github/workflows/pre-commit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 84bf39c0c..8fd45e257 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -46,7 +46,7 @@ jobs: git commit -m "pre-commit" -a fi - name: Push changes - if: failure() && startsWith(github.ref, 'refs/heads') + if: failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} From 7448c31e2f9093e4b0bd324df5de04d317dc576a Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 11 Dec 2021 12:24:12 +0100 Subject: [PATCH 088/114] add style problem --- R/addins.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/addins.R b/R/addins.R index 5e265b11f..a4f707c17 100644 --- a/R/addins.R +++ b/R/addins.R @@ -46,7 +46,7 @@ NULL #' @importFrom rlang abort #' @keywords internal -style_active_file <- function() { +style_active_file <-function() { communicate_addins_style_transformers() context <- get_rstudio_context() transformer <- make_transformer(get_addins_style_transformer(), From b9ad4c1728a87ed42acb51eae41200ce1be82e1c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 11 Dec 2021 11:25:58 +0000 Subject: [PATCH 089/114] pre-commit --- R/addins.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/addins.R b/R/addins.R index a4f707c17..5e265b11f 100644 --- a/R/addins.R +++ b/R/addins.R @@ -46,7 +46,7 @@ NULL #' @importFrom rlang abort #' @keywords internal -style_active_file <-function() { +style_active_file <- function() { communicate_addins_style_transformers() context <- get_rstudio_context() transformer <- make_transformer(get_addins_style_transformer(), From 60232840b626548dbe117ef47113ccb4bfa212df Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 11 Dec 2021 12:29:24 +0100 Subject: [PATCH 090/114] restore initial --- .github/workflows/pre-commit.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 8fd45e257..0cdf2e517 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -1,9 +1,9 @@ name: pre-commit on: push: - branches: - - main - - master + branches-ignore: + - 'master' + - 'main' pull_request: types: [opened, synchronize, reopened, ready_for_review] @@ -46,7 +46,7 @@ jobs: git commit -m "pre-commit" -a fi - name: Push changes - if: failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') + if: failure() && startsWith(github.ref, 'refs/heads') uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} From 462b01cf16ad472da873be4fd70df859d206d3b9 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Fri, 17 Dec 2021 00:22:15 +0100 Subject: [PATCH 091/114] move pipe adder one level up so we have the context of the enclosing call and can check if it's substitute or not. Note that this won't work if substitute itself is a placeholder (see issue) --- NEWS.md | 2 + R/rules-tokens.R | 7 ++++ tests/testthat/test-token_adding_removing.R | 6 +++ .../token_adding_removing/substitute-in.R | 3 ++ .../token_adding_removing/substitute-in_tree | 39 +++++++++++++++++++ .../token_adding_removing/substitute-out.R | 3 ++ 6 files changed, 60 insertions(+) create mode 100644 tests/testthat/token_adding_removing/substitute-in.R create mode 100644 tests/testthat/token_adding_removing/substitute-in_tree create mode 100644 tests/testthat/token_adding_removing/substitute-out.R diff --git a/NEWS.md b/NEWS.md index 178ea8380..ee5927374 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # styler 1.6.2.9000 (Development version) +* Piped function without brackets `substitute(x %>% y)` don't get `()` added + anymore, as this can change outcome of the code (#876). * Alignment detection respects stylerignore (#850). * Add vignette on distributing style guide (#846, #861). * Enable pre-commit.ci (#843). diff --git a/R/rules-tokens.R b/R/rules-tokens.R index d0517499b..50ddc1a59 100644 --- a/R/rules-tokens.R +++ b/R/rules-tokens.R @@ -17,6 +17,13 @@ resolve_semicolon <- function(pd) { } add_brackets_in_pipe <- function(pd) { + if (!identical(pd$text[next_non_comment(pd, 0L)], "substitute")) { + pd$child <- map(pd$child, add_brackets_in_pipe_child) + } + pd +} + +add_brackets_in_pipe_child <- function(pd) { is_pipe <- pd$token %in% c("SPECIAL-PIPE", "PIPE") Reduce(add_brackets_in_pipe_one, which(is_pipe), init = pd) } diff --git a/tests/testthat/test-token_adding_removing.R b/tests/testthat/test-token_adding_removing.R index 2f42e5c15..0b2d2d28a 100644 --- a/tests/testthat/test-token_adding_removing.R +++ b/tests/testthat/test-token_adding_removing.R @@ -43,3 +43,9 @@ test_that("No braces are added if conditional statement is within pipe", { transformer = style_text ), NA) }) + +test_that("No brace is added within `substitute()`", { + expect_warning(test_collection("token_adding_removing", "substitute", + transformer = style_text + ), NA) +}) diff --git a/tests/testthat/token_adding_removing/substitute-in.R b/tests/testthat/token_adding_removing/substitute-in.R new file mode 100644 index 000000000..83305008d --- /dev/null +++ b/tests/testthat/token_adding_removing/substitute-in.R @@ -0,0 +1,3 @@ +expr <- substitute(airquality %>% FUN_EXPR, env = list(FUN_EXPR = call("FUN_head"))) +a %>% + x diff --git a/tests/testthat/token_adding_removing/substitute-in_tree b/tests/testthat/token_adding_removing/substitute-in_tree new file mode 100644 index 000000000..70c35013e --- /dev/null +++ b/tests/testthat/token_adding_removing/substitute-in_tree @@ -0,0 +1,39 @@ +ROOT (token: short_text [lag_newlines/spaces] {pos_id}) + ¦--expr: expr [0/0] {1} + ¦ ¦--expr: expr [0/1] {3} + ¦ ¦ °--SYMBOL: expr [0/0] {2} + ¦ ¦--LEFT_ASSIGN: <- [0/1] {4} + ¦ °--expr: subst [0/0] {5} + ¦ ¦--expr: subst [0/0] {7} + ¦ ¦ °--SYMBOL_FUNCTION_CALL: subst [0/0] {6} + ¦ ¦--'(': ( [0/0] {8} + ¦ ¦--expr: airqu [0/0] {9} + ¦ ¦ ¦--expr: airqu [0/1] {11} + ¦ ¦ ¦ °--SYMBOL: airqu [0/0] {10} + ¦ ¦ ¦--SPECIAL-PIPE: %>% [0/1] {12} + ¦ ¦ °--expr: FUN_E [0/0] {14} + ¦ ¦ °--SYMBOL: FUN_E [0/0] {13} + ¦ ¦--',': , [0/1] {15} + ¦ ¦--SYMBOL_SUB: env [0/1] {16} + ¦ ¦--EQ_SUB: = [0/1] {17} + ¦ ¦--expr: list( [0/0] {18} + ¦ ¦ ¦--expr: list [0/0] {20} + ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: list [0/0] {19} + ¦ ¦ ¦--'(': ( [0/0] {21} + ¦ ¦ ¦--SYMBOL_SUB: FUN_E [0/1] {22} + ¦ ¦ ¦--EQ_SUB: = [0/1] {23} + ¦ ¦ ¦--expr: call( [0/0] {24} + ¦ ¦ ¦ ¦--expr: call [0/0] {26} + ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: call [0/0] {25} + ¦ ¦ ¦ ¦--'(': ( [0/0] {27} + ¦ ¦ ¦ ¦--expr: "FUN_ [0/0] {29} + ¦ ¦ ¦ ¦ °--STR_CONST: "FUN_ [0/0] {28} + ¦ ¦ ¦ °--')': ) [0/0] {30} + ¦ ¦ °--')': ) [0/0] {31} + ¦ °--')': ) [0/0] {32} + °--expr: a %>% [1/0] {33} + ¦--expr: a [0/1] {35} + ¦ °--SYMBOL: a [0/0] {34} + ¦--SPECIAL-PIPE: %>% [0/2] {36} + °--expr: x [1/0] {38} + °--SYMBOL: x [0/0] {37} diff --git a/tests/testthat/token_adding_removing/substitute-out.R b/tests/testthat/token_adding_removing/substitute-out.R new file mode 100644 index 000000000..415d84d87 --- /dev/null +++ b/tests/testthat/token_adding_removing/substitute-out.R @@ -0,0 +1,3 @@ +expr <- substitute(airquality %>% FUN_EXPR, env = list(FUN_EXPR = call("FUN_head"))) +a %>% + x() From 4daeb61b5891a294182798536db9e3fcb97e1b74 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 19 Dec 2021 17:40:04 +0100 Subject: [PATCH 092/114] remove trees --- .Rbuildignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.Rbuildignore b/.Rbuildignore index 1eec28edc..a2758dc9d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -23,3 +23,4 @@ revdep ^LICENSE\.md$ ^inst/hooks/$ ^inst/WORDLIST$ +^.*-in_tree$ From 8680dc0684a9208116a68a2313b9d268242a2649 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 19 Dec 2021 17:44:38 +0100 Subject: [PATCH 093/114] ignore more for built --- .Rbuildignore | 3 ++- NEWS.md | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.Rbuildignore b/.Rbuildignore index a2758dc9d..5627a6b1f 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -21,6 +21,7 @@ revdep ^touchstone$ ^\.github$ ^LICENSE\.md$ -^inst/hooks/$ +^inst/hooks/.*$ ^inst/WORDLIST$ ^.*-in_tree$ +^vignettes/gsoc_proposal$ diff --git a/NEWS.md b/NEWS.md index 05090dff0..585f193ba 100644 --- a/NEWS.md +++ b/NEWS.md @@ -32,6 +32,8 @@ As a consequence of this approach, the defaults for `styler.ignore_start` and `styler.ignore_stop` omit the `#` (#849). +* the built package size has been reduced by ~50% by listing `*-in_tree` files + in `.Rbuildignore` (#879). # styler 1.6.2 From 47a7126b7e79fd7ee0ec4aabd622472fbaf7e0a9 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 23 Dec 2021 12:45:25 +0100 Subject: [PATCH 094/114] re-arrange news --- NEWS.md | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/NEWS.md b/NEWS.md index 05090dff0..a382a5f19 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,21 +1,11 @@ # styler 1.6.2.9000 (Development version) -* Piped function without brackets `substitute(x %>% y)` don't get `()` added - anymore, as this can change outcome of the code (#876). -* Alignment detection respects stylerignore (#850). -* Add vignette on distributing style guide (#846, #861). -* Enable pre-commit.ci (#843). +**API changes** + * new R option `styler.cache_root` (defaulting to `"styler"`) that determines the sub-directory under the {R.cache} cache directory that {styler} uses. Non- default caches won't be cleaned up by {styler}. We suggest `"styler-perm"` (also used by {precommit}). -* rename default branch to main (#859). -* Fix argument name `filetype` in Example for `style_dir()` (#855). -* ensure a trailing blank line also if the input is cached (#867). -* Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which - allowed to remove the dependency at {backports} and some exception handling. -* Remove dependency on {xfun} (#866). -* use pre-commit via GitHub Actions (#872). * stylerignore markers are now interpreted as regular expressions instead of comments that must match exactly. This allows to specify multiple markers in @@ -33,6 +23,28 @@ `styler.ignore_stop` omit the `#` (#849). +* Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which + allowed to remove the dependency at {backports} and some exception handling. + +**Other changes** + +* Piped function without brackets `substitute(x %>% y)` don't get `()` added + anymore, as this can change outcome of the code (#876). +* Alignment detection respects stylerignore (#850). +* Unaligned expressions with quoted key (e.g. `c("x" = 2)`) are now correctly + detected (#881). +* Add vignette on distributing style guide (#846, #861). +* ensure a trailing blank line also if the input is cached (#867). +* Fix argument name `filetype` in Example for `style_dir()` (#855). + +**Infrastructure** + +* Remove dependency on {xfun} (#866). +* rename default branch to main (#859). +* Enable pre-commit.ci (#843). +* use pre-commit via GitHub Actions (#872). + + # styler 1.6.2 * clean up cache files older than one week (#842). From 483334063a162b12b0f32b3b8fd519078a024d67 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 23 Dec 2021 12:52:43 +0100 Subject: [PATCH 095/114] quoted key does not mean aligned per se --- R/detect-alignment-utils.R | 3 +- tests/testthat/alignment/quoted-names-in.R | 7 ++++ tests/testthat/alignment/quoted-names-in_tree | 39 +++++++++++++++++++ tests/testthat/alignment/quoted-names-out.R | 7 ++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/alignment/quoted-names-in.R create mode 100644 tests/testthat/alignment/quoted-names-in_tree create mode 100644 tests/testthat/alignment/quoted-names-out.R diff --git a/R/detect-alignment-utils.R b/R/detect-alignment-utils.R index cb86f4bb5..eb5cb04bc 100644 --- a/R/detect-alignment-utils.R +++ b/R/detect-alignment-utils.R @@ -80,7 +80,8 @@ alignment_col1_all_named <- function(relevant_pd_by_line) { if (nrow(x) < 3) { return(FALSE) } - identical(x$token[c(1, 3)], c("SYMBOL_SUB", "expr")) && + x$token[3] == "expr" && + x$token[1] %in% c("SYMBOL_SUB", "STR_CONST") && x$token[2] %in% c( "EQ_SUB", "SPECIAL-IN", "LT", "GT", "EQ", "NE" ) diff --git a/tests/testthat/alignment/quoted-names-in.R b/tests/testthat/alignment/quoted-names-in.R new file mode 100644 index 000000000..f221f97e6 --- /dev/null +++ b/tests/testthat/alignment/quoted-names-in.R @@ -0,0 +1,7 @@ +df <- dplyr::rename(df, + "xValues" = "Time", + "xUnit" = "TimeUnit", + "yValues" = "simulationValues", + "yUnit" = "unit", + "yDimension" = "dimension" +) diff --git a/tests/testthat/alignment/quoted-names-in_tree b/tests/testthat/alignment/quoted-names-in_tree new file mode 100644 index 000000000..0ed87be9c --- /dev/null +++ b/tests/testthat/alignment/quoted-names-in_tree @@ -0,0 +1,39 @@ +ROOT (token: short_text [lag_newlines/spaces] {pos_id}) + °--expr: df <- [0/0] {1} + ¦--expr: df [0/1] {3} + ¦ °--SYMBOL: df [0/0] {2} + ¦--LEFT_ASSIGN: <- [0/1] {4} + °--expr: dplyr [0/0] {5} + ¦--expr: dplyr [0/0] {6} + ¦ ¦--SYMBOL_PACKAGE: dplyr [0/0] {7} + ¦ ¦--NS_GET: :: [0/0] {8} + ¦ °--SYMBOL_FUNCTION_CALL: renam [0/0] {9} + ¦--'(': ( [0/0] {10} + ¦--expr: df [0/0] {12} + ¦ °--SYMBOL: df [0/0] {11} + ¦--',': , [0/2] {13} + ¦--STR_CONST: "xVal [1/1] {14} + ¦--EQ_SUB: = [0/3] {15} + ¦--expr: "Time [0/0] {17} + ¦ °--STR_CONST: "Time [0/0] {16} + ¦--',': , [0/2] {18} + ¦--STR_CONST: "xUni [1/1] {19} + ¦--EQ_SUB: = [0/1] {20} + ¦--expr: "Time [0/0] {22} + ¦ °--STR_CONST: "Time [0/0] {21} + ¦--',': , [0/2] {23} + ¦--STR_CONST: "yVal [1/3] {24} + ¦--EQ_SUB: = [0/1] {25} + ¦--expr: "simu [0/0] {27} + ¦ °--STR_CONST: "simu [0/0] {26} + ¦--',': , [0/2] {28} + ¦--STR_CONST: "yUni [1/1] {29} + ¦--EQ_SUB: = [0/1] {30} + ¦--expr: "unit [0/0] {32} + ¦ °--STR_CONST: "unit [0/0] {31} + ¦--',': , [0/2] {33} + ¦--STR_CONST: "yDim [1/2] {34} + ¦--EQ_SUB: = [0/1] {35} + ¦--expr: "dime [0/0] {37} + ¦ °--STR_CONST: "dime [0/0] {36} + °--')': ) [1/0] {38} diff --git a/tests/testthat/alignment/quoted-names-out.R b/tests/testthat/alignment/quoted-names-out.R new file mode 100644 index 000000000..1b5c481df --- /dev/null +++ b/tests/testthat/alignment/quoted-names-out.R @@ -0,0 +1,7 @@ +df <- dplyr::rename(df, + "xValues" = "Time", + "xUnit" = "TimeUnit", + "yValues" = "simulationValues", + "yUnit" = "unit", + "yDimension" = "dimension" +) From 1b0f5eaf025dd3786c22fa6da605202d66ae7d2e Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 23 Dec 2021 13:46:08 +0100 Subject: [PATCH 096/114] reject styling wrongly parsed coder --- NEWS.md | 2 ++ R/parse.R | 13 ++++++++++++- R/utils.R | 5 ++++- inst/WORDLIST | 1 + tests/testthat/test-parsing.R | 8 ++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 818e2f258..1717499b1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -38,6 +38,8 @@ * Add vignette on distributing style guide (#846, #861). * ensure a trailing blank line also if the input is cached (#867). * Fix argument name `filetype` in Example for `style_dir()` (#855). +* An error is now thrown on styling if input unicode characters can't be + correctly parsed for Windows and R < 4.2 (#883). **Infrastructure** diff --git a/R/parse.R b/R/parse.R index a82c60637..f7173ff2a 100644 --- a/R/parse.R +++ b/R/parse.R @@ -97,7 +97,18 @@ get_parse_data <- function(text, include_text = TRUE, ...) { pd <- as_tibble( utils::getParseData(parsed, includeText = include_text), .name_repair = "minimal" - ) %>% + ) + if (getRversion() < "4.2") { + is_unicode_parsing_error <- grepl("^\"\"$", pd$text) + if (any(is_unicode_parsing_error)) { + rlang::abort( + "Can't parse input due to unicode restriction in base R. Please ", + "upgrade R to style this input. ", + "Context: https://github.com/r-lib/styler/issues/847" + ) + } + } + pd <- pd %>% add_id_and_short() parser_version_set(parser_version_find(pd)) diff --git a/R/utils.R b/R/utils.R index abc867000..af6260055 100644 --- a/R/utils.R +++ b/R/utils.R @@ -70,6 +70,9 @@ even_index <- function(x) { seq(2L, length(x), by = 2) } +is_windows <- function() { + identical(.Platform$OS.type, "windows") +} #' Invoke a system command #' @@ -79,7 +82,7 @@ even_index <- function(x) { #' @param ... Arguments passed to [shell()] or [system()]. #' @keywords internal calls_sys <- function(sys_call, ...) { - if (Sys.info()[1] == "Windows") { + if (is_windows()) { error <- shell(sys_call, ...) } else { error <- system(sys_call, ...) diff --git a/inst/WORDLIST b/inst/WORDLIST index e01a1a2db..042f8a762 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -243,6 +243,7 @@ ubuntu ui uncached unexplainable +unicode unindent unindention unlink diff --git a/tests/testthat/test-parsing.R b/tests/testthat/test-parsing.R index 73d0db1cf..2b4707d3b 100644 --- a/tests/testthat/test-parsing.R +++ b/tests/testthat/test-parsing.R @@ -63,3 +63,11 @@ test_that("mixed CRLF / LF EOLs fail", { "unexpected input" ) }) + +test_that("unicode can't be propprely handled on Windows for R < 4.2", { + msg <- ifelse(getRversion() < 4.2 && is_windows(), + "Can't parse input due to unicode restriction in base R\\.", + NA + ) + expect_error(style_text('suit <- "♠"'), msg) +}) From 6614d3ac5e1d41675cdf0374cfdade8b40c87105 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 23 Dec 2021 14:15:59 +0100 Subject: [PATCH 097/114] add more concise advice --- R/parse.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/parse.R b/R/parse.R index f7173ff2a..46aa1d05b 100644 --- a/R/parse.R +++ b/R/parse.R @@ -103,7 +103,7 @@ get_parse_data <- function(text, include_text = TRUE, ...) { if (any(is_unicode_parsing_error)) { rlang::abort( "Can't parse input due to unicode restriction in base R. Please ", - "upgrade R to style this input. ", + "upgrade R to >= 4.2 to style this input. ", "Context: https://github.com/r-lib/styler/issues/847" ) } From ce351222bdf41a0e7f9704a75b7250e33a458ab6 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 23 Dec 2021 14:31:37 +0100 Subject: [PATCH 098/114] fix error --- R/parse.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/parse.R b/R/parse.R index 46aa1d05b..f728f4583 100644 --- a/R/parse.R +++ b/R/parse.R @@ -101,11 +101,11 @@ get_parse_data <- function(text, include_text = TRUE, ...) { if (getRversion() < "4.2") { is_unicode_parsing_error <- grepl("^\"\"$", pd$text) if (any(is_unicode_parsing_error)) { - rlang::abort( + rlang::abort(paste0( "Can't parse input due to unicode restriction in base R. Please ", "upgrade R to >= 4.2 to style this input. ", "Context: https://github.com/r-lib/styler/issues/847" - ) + )) } } pd <- pd %>% From 2b886c42e42108241d2f55a80705135fce807533 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 23 Dec 2021 20:06:37 +0100 Subject: [PATCH 099/114] preserve trailing blank line --- NEWS.md | 1 + R/roxygen-examples.R | 10 +++++-- .../17-two-no-non-comment-out.R | 1 + .../26-empty-trailing-lines-in.R | 30 +++++++++++++++++++ .../26-empty-trailing-lines-in_tree | 30 +++++++++++++++++++ .../26-empty-trailing-lines-out.R | 24 +++++++++++++++ .../testthat/test-roxygen-examples-complete.R | 5 ++++ 7 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-in.R create mode 100644 tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-in_tree create mode 100644 tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-out.R diff --git a/NEWS.md b/NEWS.md index 1717499b1..bd63665aa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -37,6 +37,7 @@ detected (#881). * Add vignette on distributing style guide (#846, #861). * ensure a trailing blank line also if the input is cached (#867). +* Preserve trailing blank line in roxygen examples (#880). * Fix argument name `filetype` in Example for `style_dir()` (#855). * An error is now thrown on styling if input unicode characters can't be correctly parsed for Windows and R < 4.2 (#883). diff --git a/R/roxygen-examples.R b/R/roxygen-examples.R index 0b880ccd3..67a1576b0 100644 --- a/R/roxygen-examples.R +++ b/R/roxygen-examples.R @@ -102,6 +102,9 @@ style_roxygen_example_snippet <- function(code_snippet, mask <- decomposed$mask } code_snippet <- post_parse_roxygen(code_snippet) + append_empty <- !is_dont && + length(code_snippet) > 1L && + last(code_snippet) == "" cache_is_active <- cache_is_activated() is_cached <- is_cached( @@ -116,10 +119,13 @@ style_roxygen_example_snippet <- function(code_snippet, parse_transform_serialize_r(transformers, base_indention = base_indention, warn_empty = FALSE ) - } else { - code_snippet <- ensure_last_n_empty(code_snippet, n = 0) } + code_snippet <- ensure_last_n_empty( + code_snippet, + n = ifelse(append_empty, 1L, 0L) + ) + if (!is_cached && cache_is_active) { cache_write( code_snippet, transformers, diff --git a/tests/testthat/roxygen-examples-complete/17-two-no-non-comment-out.R b/tests/testthat/roxygen-examples-complete/17-two-no-non-comment-out.R index 975d79cb7..e5063feec 100644 --- a/tests/testthat/roxygen-examples-complete/17-two-no-non-comment-out.R +++ b/tests/testthat/roxygen-examples-complete/17-two-no-non-comment-out.R @@ -4,6 +4,7 @@ #' } #' # before this comment is a left-over space #' another_function <- function() NULL +#' #' @examples #' my_fun <- function() { #' print("hello world!") diff --git a/tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-in.R b/tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-in.R new file mode 100644 index 000000000..14b943318 --- /dev/null +++ b/tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-in.R @@ -0,0 +1,30 @@ +#' this +#' +#' mey +#' @examples +#' 2 + 1 +#' +NULL + + +#' this +#' +#' mey +#' @examples +#' 2 + 1 +#' +#' +#' +#' +#' +#' +#' +NULL + + +#' this +#' +#' mey +#' @examples +#' 2 + 1 +NULL diff --git a/tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-in_tree b/tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-in_tree new file mode 100644 index 000000000..d0f5d92d7 --- /dev/null +++ b/tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-in_tree @@ -0,0 +1,30 @@ +ROOT (token: short_text [lag_newlines/spaces] {pos_id}) + ¦--COMMENT: #' th [0/0] {1} + ¦--COMMENT: #' [1/0] {2} + ¦--COMMENT: #' me [1/0] {3} + ¦--COMMENT: #' @e [1/0] {4} + ¦--COMMENT: #' 2 [1/0] {5} + ¦--COMMENT: #' [1/0] {6} + ¦--expr: NULL [1/0] {8} + ¦ °--NULL_CONST: NULL [0/0] {7} + ¦--COMMENT: #' th [3/0] {9} + ¦--COMMENT: #' [1/0] {10} + ¦--COMMENT: #' me [1/0] {11} + ¦--COMMENT: #' @e [1/0] {12} + ¦--COMMENT: #' 2 [1/0] {13} + ¦--COMMENT: #' [1/0] {14} + ¦--COMMENT: #' [1/0] {15} + ¦--COMMENT: #' [1/0] {16} + ¦--COMMENT: #' [1/0] {17} + ¦--COMMENT: #' [1/0] {18} + ¦--COMMENT: #' [1/0] {19} + ¦--COMMENT: #' [1/0] {20} + ¦--expr: NULL [1/0] {22} + ¦ °--NULL_CONST: NULL [0/0] {21} + ¦--COMMENT: #' th [3/0] {23} + ¦--COMMENT: #' [1/0] {24} + ¦--COMMENT: #' me [1/0] {25} + ¦--COMMENT: #' @e [1/0] {26} + ¦--COMMENT: #' 2 [1/0] {27} + °--expr: NULL [1/0] {29} + °--NULL_CONST: NULL [0/0] {28} diff --git a/tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-out.R b/tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-out.R new file mode 100644 index 000000000..e9f4c3d17 --- /dev/null +++ b/tests/testthat/roxygen-examples-complete/26-empty-trailing-lines-out.R @@ -0,0 +1,24 @@ +#' this +#' +#' mey +#' @examples +#' 2 + 1 +#' +NULL + + +#' this +#' +#' mey +#' @examples +#' 2 + 1 +#' +NULL + + +#' this +#' +#' mey +#' @examples +#' 2 + 1 +NULL diff --git a/tests/testthat/test-roxygen-examples-complete.R b/tests/testthat/test-roxygen-examples-complete.R index 2a39060ae..861feefbe 100644 --- a/tests/testthat/test-roxygen-examples-complete.R +++ b/tests/testthat/test-roxygen-examples-complete.R @@ -131,4 +131,9 @@ test_that("analogous to test-roxygen-examples-complete", { "roxygen-examples-complete", "^25", transformer = style_text ), NA) + + expect_warning(test_collection( + "roxygen-examples-complete", "^26", + transformer = style_text + ), NA) }) From bfe2e82479824f5ceef3c48168983a24a26cb044 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 23 Dec 2021 20:14:25 +0100 Subject: [PATCH 100/114] fix invalid braces --- .../12-fun-decs-in-examples-in.R | 2 +- .../12-fun-decs-in-examples-in_tree | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/testthat/roxygen-examples-complete/12-fun-decs-in-examples-in.R b/tests/testthat/roxygen-examples-complete/12-fun-decs-in-examples-in.R index efb7c0f47..225435fdc 100644 --- a/tests/testthat/roxygen-examples-complete/12-fun-decs-in-examples-in.R +++ b/tests/testthat/roxygen-examples-complete/12-fun-decs-in-examples-in.R @@ -65,7 +65,6 @@ create_style_guide <- function(initialize = default_style_guide_attributes, #' op<- pd_flat$token %in% "}" #' } #' op <-pd_flat$token %in% "'['" -#' } #' \donttest{ #' op <- pd_flat$token %in% "']'" #' } @@ -74,4 +73,5 @@ create_style_guide <- function(initialize = default_style_guide_attributes, #' } #' \donttest{ #' op <- pd_flat$token %in%"]" +#' } NULL diff --git a/tests/testthat/roxygen-examples-complete/12-fun-decs-in-examples-in_tree b/tests/testthat/roxygen-examples-complete/12-fun-decs-in-examples-in_tree index 3a38f0d13..930abc1cd 100644 --- a/tests/testthat/roxygen-examples-complete/12-fun-decs-in-examples-in_tree +++ b/tests/testthat/roxygen-examples-complete/12-fun-decs-in-examples-in_tree @@ -138,14 +138,14 @@ ROOT (token: short_text [lag_newlines/spaces] {pos_id}) ¦--COMMENT: #' op [1/0] {134} ¦--COMMENT: #' } [1/0] {135} ¦--COMMENT: #' op [1/0] {136} - ¦--COMMENT: #' } [1/0] {137} - ¦--COMMENT: #' \d [1/0] {138} - ¦--COMMENT: #' op [1/0] {139} - ¦--COMMENT: #' } [1/0] {140} - ¦--COMMENT: #' \d [1/0] {141} - ¦--COMMENT: #' op [1/0] {142} - ¦--COMMENT: #' } [1/0] {143} - ¦--COMMENT: #' \d [1/0] {144} - ¦--COMMENT: #' op [1/0] {145} + ¦--COMMENT: #' \d [1/0] {137} + ¦--COMMENT: #' op [1/0] {138} + ¦--COMMENT: #' } [1/0] {139} + ¦--COMMENT: #' \d [1/0] {140} + ¦--COMMENT: #' op [1/0] {141} + ¦--COMMENT: #' } [1/0] {142} + ¦--COMMENT: #' \d [1/0] {143} + ¦--COMMENT: #' op [1/0] {144} + ¦--COMMENT: #' } [1/0] {145} °--expr: NULL [1/0] {147} °--NULL_CONST: NULL [0/0] {146} From 1744cb3983a5b9abc5cab6bf09648dfbf6203d87 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Fri, 24 Dec 2021 09:00:35 +0100 Subject: [PATCH 101/114] Update NEWS.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kirill Müller --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index bd63665aa..92874cf74 100644 --- a/NEWS.md +++ b/NEWS.md @@ -37,7 +37,7 @@ detected (#881). * Add vignette on distributing style guide (#846, #861). * ensure a trailing blank line also if the input is cached (#867). -* Preserve trailing blank line in roxygen examples (#880). +* Preserve trailing blank line in roxygen examples to simplify concatenation of examples (#880). * Fix argument name `filetype` in Example for `style_dir()` (#855). * An error is now thrown on styling if input unicode characters can't be correctly parsed for Windows and R < 4.2 (#883). From e9dfce3d819b23bd1ebb123eb2ba5dc1f739d2ae Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 25 Dec 2021 16:46:17 +0100 Subject: [PATCH 102/114] internal api should handle empty strings more grateful, yet not 100% consistent --- R/roxygen-examples.R | 2 ++ R/transform-files.R | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/R/roxygen-examples.R b/R/roxygen-examples.R index 67a1576b0..8c3698876 100644 --- a/R/roxygen-examples.R +++ b/R/roxygen-examples.R @@ -70,6 +70,8 @@ style_roxygen_code_example_segment <- function(one_dont, base_indention) { if (length(one_dont) < 1L) { return(character()) + } else if (identical(one_dont, "\n")) { + return(character(1L)) } dont_seqs <- find_dont_seqs(one_dont) split_segments <- split_roxygen_segments(one_dont, unlist(dont_seqs)) diff --git a/R/transform-files.R b/R/transform-files.R index 6a5d29c06..839245bc5 100644 --- a/R/transform-files.R +++ b/R/transform-files.R @@ -270,13 +270,17 @@ parse_transform_serialize_r <- function(text, #' @keywords internal #' @seealso specify_transformers_drop transformers_drop <- function(text, transformers) { - is_colon <- text == ";" - if (any(is_colon)) { - # ; can only be parsed when on the same line as other token, not the case - # here since text is output of compute_parse_data_nested. - text <- c(text[!is_colon], "1;") + if (length(text) > 0) { + is_colon <- text == ";" + if (any(is_colon)) { + # ; can only be parsed when on the same line as other token, not the case + # here since text is output of compute_parse_data_nested. + text <- c(text[!is_colon], "1;") + } + token <- unique(tokenize(text)$token) + } else { + token <- character() } - token <- unique(tokenize(text)$token) for (scope in c("line_break", "space", "token", "indention")) { rules <- transformers$transformers_drop[[scope]] for (rule in names(rules)) { From 009b3d107ca36b2371c5ed11f108744ddc20d0d5 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 25 Dec 2021 16:49:18 +0100 Subject: [PATCH 103/114] latest pre-commit --- .pre-commit-config.yaml | 4 ++-- NEWS.md | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 71bd1be0d..0f84295de 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.9139 + rev: v0.2.2.9006 hooks: - id: style-files args: [--style_pkg=styler, --style_fun=tidyverse_style] @@ -78,7 +78,7 @@ repos: tests/testthat/.*\.R(md)? )$ - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.1.0 hooks: - id: check-added-large-files args: ['--maxkb=200'] diff --git a/NEWS.md b/NEWS.md index 92874cf74..0aa8983f3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -32,16 +32,18 @@ * Piped function without brackets `substitute(x %>% y)` don't get `()` added anymore, as this can change outcome of the code (#876). +* Add vignette on distributing style guide (#846, #861). * Alignment detection respects stylerignore (#850). +* `Warning: Unknown or uninitialised column:` was fixed (#885). * Unaligned expressions with quoted key (e.g. `c("x" = 2)`) are now correctly detected (#881). -* Add vignette on distributing style guide (#846, #861). * ensure a trailing blank line also if the input is cached (#867). * Preserve trailing blank line in roxygen examples to simplify concatenation of examples (#880). * Fix argument name `filetype` in Example for `style_dir()` (#855). * An error is now thrown on styling if input unicode characters can't be correctly parsed for Windows and R < 4.2 (#883). + **Infrastructure** * Remove dependency on {xfun} (#866). From c4bc8e6d587b4242aa1ede5b15ee8a7ddf0ef056 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 25 Dec 2021 17:01:52 +0100 Subject: [PATCH 104/114] add a test --- tests/testthat/test-transformers-drop.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/testthat/test-transformers-drop.R b/tests/testthat/test-transformers-drop.R index 79cab1e76..b0fafbcae 100644 --- a/tests/testthat/test-transformers-drop.R +++ b/tests/testthat/test-transformers-drop.R @@ -31,6 +31,17 @@ t_empty_drop2 <- create_style_guide( transformers_drop = list(), ) +test_that("empty string as input can be handled", { + t_new <- transformers_drop( + "", t + ) + + t_new2 <- transformers_drop( + character(), t + ) + expect_equal(t_new, t_new2) +}) + test_that("transformers are not removed if they are used", { t_new <- transformers_drop( "!x", t From 4dad8ac21b7cd2a4ebf34ab7595b14af06fd226a Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 25 Dec 2021 17:39:14 +0100 Subject: [PATCH 105/114] fix pre-commit --- .pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0f84295de..7c1572270 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -52,7 +52,8 @@ repos: exclude: > (?x)^( tests/testthat/public-api/xyzaddin/addin_region-.*| - tests/testmanual/addins/r-invalid\.R| + tests/testmanual/addins/.*invalid.*| + tests/testthat/rmd/no-tidy-out\.Rmd| tests/testthat/escaping/basic-escape-out\.R| tests/testthat/indention_operators/.*pipe.*| tests/testthat/line_breaks_and_other/.*pipe.*| From 321d3ee4aeb67d711787c309865f381a5c6f9c6e Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 25 Dec 2021 18:28:22 +0100 Subject: [PATCH 106/114] always use keyword invalid for unparsable --- .pre-commit-config.yaml | 2 +- .../public-api/xyzfile_rmd/{random4.Rmd => invalid4.Rmd} | 0 .../public-api/xyzfile_rmd/{random7.Rmd => invalid7.Rmd} | 0 tests/testthat/test-public_api.R | 4 ++-- 4 files changed, 3 insertions(+), 3 deletions(-) rename tests/testthat/public-api/xyzfile_rmd/{random4.Rmd => invalid4.Rmd} (100%) rename tests/testthat/public-api/xyzfile_rmd/{random7.Rmd => invalid7.Rmd} (100%) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7c1572270..aefae54c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -52,7 +52,7 @@ repos: exclude: > (?x)^( tests/testthat/public-api/xyzaddin/addin_region-.*| - tests/testmanual/addins/.*invalid.*| + tests/.*invalid.*| tests/testthat/rmd/no-tidy-out\.Rmd| tests/testthat/escaping/basic-escape-out\.R| tests/testthat/indention_operators/.*pipe.*| diff --git a/tests/testthat/public-api/xyzfile_rmd/random4.Rmd b/tests/testthat/public-api/xyzfile_rmd/invalid4.Rmd similarity index 100% rename from tests/testthat/public-api/xyzfile_rmd/random4.Rmd rename to tests/testthat/public-api/xyzfile_rmd/invalid4.Rmd diff --git a/tests/testthat/public-api/xyzfile_rmd/random7.Rmd b/tests/testthat/public-api/xyzfile_rmd/invalid7.Rmd similarity index 100% rename from tests/testthat/public-api/xyzfile_rmd/random7.Rmd rename to tests/testthat/public-api/xyzfile_rmd/invalid7.Rmd diff --git a/tests/testthat/test-public_api.R b/tests/testthat/test-public_api.R index 5226db1cb..d7653d3b2 100644 --- a/tests/testthat/test-public_api.R +++ b/tests/testthat/test-public_api.R @@ -165,12 +165,12 @@ test_that("styler can style Rmarkdown file", { test_that("styler handles malformed Rmd file and invalid R code in chunk", { capture_output(expect_warning( - style_file(testthat_file("public-api", "xyzfile_rmd", "random4.Rmd"), strict = FALSE), + style_file(testthat_file("public-api", "xyzfile_rmd", "invalid4.Rmd"), strict = FALSE), "3: " )) capture_output(expect_warning( - style_file(testthat_file("public-api", "xyzfile_rmd", "random7.Rmd"), strict = FALSE), + style_file(testthat_file("public-api", "xyzfile_rmd", "invalid7.Rmd"), strict = FALSE), "Malformed file" )) }) From 027c8a03c244fe9871f0a6e6a20a413c6e692d48 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 25 Dec 2021 18:41:31 +0100 Subject: [PATCH 107/114] more renaming --- tests/testthat/rmd/{no-tidy-in.Rmd => invalid-in.Rmd} | 0 tests/testthat/rmd/{no-tidy-out.Rmd => invalid-out.Rmd} | 0 tests/testthat/test-rmd.R | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename tests/testthat/rmd/{no-tidy-in.Rmd => invalid-in.Rmd} (100%) rename tests/testthat/rmd/{no-tidy-out.Rmd => invalid-out.Rmd} (100%) diff --git a/tests/testthat/rmd/no-tidy-in.Rmd b/tests/testthat/rmd/invalid-in.Rmd similarity index 100% rename from tests/testthat/rmd/no-tidy-in.Rmd rename to tests/testthat/rmd/invalid-in.Rmd diff --git a/tests/testthat/rmd/no-tidy-out.Rmd b/tests/testthat/rmd/invalid-out.Rmd similarity index 100% rename from tests/testthat/rmd/no-tidy-out.Rmd rename to tests/testthat/rmd/invalid-out.Rmd diff --git a/tests/testthat/test-rmd.R b/tests/testthat/test-rmd.R index fe44364c2..5a126de01 100644 --- a/tests/testthat/test-rmd.R +++ b/tests/testthat/test-rmd.R @@ -22,7 +22,7 @@ test_that("can style .Rmd files", { write_tree = FALSE ), NA) - expect_warning(test_collection("rmd", "no-tidy", + expect_warning(test_collection("rmd", "invalid", transformer = transform_mixed, transformer_fun = style_text, filetype = "Rmd", From c3b731f0ff86f3a1fd32372a21d55ce12f1c3ffb Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 25 Dec 2021 23:40:03 +0100 Subject: [PATCH 108/114] add new hooks --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aefae54c5..a3e8f1e68 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -91,6 +91,10 @@ repos: tests/testthat/parse_comments/eol_eof_spaces-.*| tests/testthat/reference-objects/.*| )$ +- repo: https://github.com/lorenzwalthert/gitignore-tidy + rev: b3eaceb0bf2df137cc80f85b3943b6684f204c48 + hooks: + - id: tidy-gitignore - repo: local hooks: - id: forbid-to-commit From 090ccbd34f012bc40a17313ed27b6bfbc7305ca0 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 25 Dec 2021 23:50:41 +0100 Subject: [PATCH 109/114] re-order --- .gitignore | 14 +++++++------- .pre-commit-config.yaml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 1c9463492..930a72e86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,16 @@ +.RData +.Rhistory +.Rproj.user +.gitsum Meta +R/scratch doc -.Rproj.user -.Rhistory -.RData -inst/doc docs -.gitsum gitsum -R/scratch +inst/doc revdep/ !revdep/*.md !revdep/problems.md touchstone/* -!touchstone/script.R !touchstone/config.json +!touchstone/script.R diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a3e8f1e68..d79754ac6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -92,7 +92,7 @@ repos: tests/testthat/reference-objects/.*| )$ - repo: https://github.com/lorenzwalthert/gitignore-tidy - rev: b3eaceb0bf2df137cc80f85b3943b6684f204c48 + rev: 877130576f072139e2cec2f847c85e87696e358b hooks: - id: tidy-gitignore - repo: local From 1c55a52d506e81054bf33deb5c7915c4fd9db43a Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 25 Dec 2021 23:57:27 +0100 Subject: [PATCH 110/114] sort Rbuildignore --- .Rbuildignore | 35 ++++++++++++++++------------------- .pre-commit-config.yaml | 4 +++- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 5627a6b1f..0f7c0b657 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,27 +1,24 @@ -^Meta$ -^doc$ +^.*-in_tree$ ^.*\.Rproj$ -^\.Rproj\.user$ ^API$ -^README\.Rmd$ +^CONTRIBUTING\.md$ +^LICENSE\.md$ +^Meta$ ^README-.*\.png$ -^appveyor\.yml$ -^tic\.R$ -^docs$ -^_pkgdown\.yml$ -CONTRIBUTING.md +^README\.Rmd$ +^\.Rproj\.user$ +^\.github$ ^\.gitsum$ -^gitsum$ -revdep +^\.pre-commit-config\.yaml$ +^_pkgdown\.yml$ ^cran-comments\.md$ +^doc$ +^docs$ +^gitsum$ +^inst/WORDLIST$ +^inst/hooks/.*$ +^revdep$ ^tests/testmanual$ -^\.pre-commit-config\.yaml$ -^brew\-log$ -^\.github/$ +^tic\.R$ ^touchstone$ -^\.github$ -^LICENSE\.md$ -^inst/hooks/.*$ -^inst/WORDLIST$ -^.*-in_tree$ ^vignettes/gsoc_proposal$ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d79754ac6..042487162 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -83,6 +83,8 @@ repos: hooks: - id: check-added-large-files args: ['--maxkb=200'] + - id: file-contents-sorter + files: "\\.Rbuildignore$" - id: end-of-file-fixer exclude: > (?x)^( @@ -92,7 +94,7 @@ repos: tests/testthat/reference-objects/.*| )$ - repo: https://github.com/lorenzwalthert/gitignore-tidy - rev: 877130576f072139e2cec2f847c85e87696e358b + rev: b3eaceb0bf2df137cc80f85b3943b6684f204c48 hooks: - id: tidy-gitignore - repo: local From f60a8a67df9aefabd2436336f95974d3871e0766 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 26 Dec 2021 21:12:52 +0100 Subject: [PATCH 111/114] add more examples --- inst/WORDLIST | 1 + vignettes/distribute_custom_style_guides.Rmd | 1 + 2 files changed, 2 insertions(+) diff --git a/inst/WORDLIST b/inst/WORDLIST index 042f8a762..c994cb6bd 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -121,6 +121,7 @@ na navbar netlify netReg +nocomments NONINFRINGEMENT nph NUM diff --git a/vignettes/distribute_custom_style_guides.Rmd b/vignettes/distribute_custom_style_guides.Rmd index 94a4eaaec..496828345 100644 --- a/vignettes/distribute_custom_style_guides.Rmd +++ b/vignettes/distribute_custom_style_guides.Rmd @@ -23,6 +23,7 @@ style guide with `create_style_guide()`. There are a few packages that implement a third-party style guide that are maintained by styler contributors: +* [lorenzwalthert/styler.nocomments](https://github.com/lorenzwalthert/styler.nocomments) * [lorenzwalthert/semicoloner](https://github.com/lorenzwalthert/semicoloner) * [lorenzwalthert/oneliner](https://github.com/lorenzwalthert/oneliner) * [mlr-org/styler.mlr](https://github.com/mlr-org/styler.mlr) From 834798cffc0dc99b1a04af634c70ec2994daf5fa Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Tue, 28 Dec 2021 14:28:26 +0100 Subject: [PATCH 112/114] re-order --- NEWS.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0aa8983f3..77f97f4df 100644 --- a/NEWS.md +++ b/NEWS.md @@ -22,11 +22,6 @@ As a consequence of this approach, the defaults for `styler.ignore_start` and `styler.ignore_stop` omit the `#` (#849). -* the built package size has been reduced by ~50% by listing `*-in_tree` files - in `.Rbuildignore` (#879). - -* Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which - allowed to remove the dependency at {backports} and some exception handling. **Other changes** @@ -38,7 +33,8 @@ * Unaligned expressions with quoted key (e.g. `c("x" = 2)`) are now correctly detected (#881). * ensure a trailing blank line also if the input is cached (#867). -* Preserve trailing blank line in roxygen examples to simplify concatenation of examples (#880). +* Preserve trailing blank line in roxygen examples to simplify concatenation of + examples (#880). * Fix argument name `filetype` in Example for `style_dir()` (#855). * An error is now thrown on styling if input unicode characters can't be correctly parsed for Windows and R < 4.2 (#883). @@ -47,7 +43,12 @@ **Infrastructure** * Remove dependency on {xfun} (#866). +* Bump minimal R requirement to 3.4 in line with the + [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which + allowed to remove the dependency at {backports} and some exception handling. * rename default branch to main (#859). +* the built package size has been reduced by ~50% by listing `*-in_tree` files + in `.Rbuildignore` (#879). * Enable pre-commit.ci (#843). * use pre-commit via GitHub Actions (#872). From 8aa30925db91475292dceaca52f48cc8f87fea5b Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Tue, 28 Dec 2021 23:24:42 +0100 Subject: [PATCH 113/114] Only one concurrent build from each group from https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#concurrency to https://github.com/actions/checkout/issues/58 and https://docs.github.com/en/actions/learn-github-actions/contexts#github-context --- .github/workflows/R-CMD-check.yaml | 5 +++++ .github/workflows/cancel.yaml | 13 ------------- .github/workflows/test-coverage.yaml | 5 +++++ 3 files changed, 10 insertions(+), 13 deletions(-) delete mode 100644 .github/workflows/cancel.yaml diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 74b28bdd7..d0fcc49f2 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -16,6 +16,11 @@ on: name: R-CMD-check +concurrency: + group: ${{ github.action }}-${{ github.event_path }} + cancel-in-progress: true + + jobs: R-CMD-check: runs-on: ${{ matrix.config.os }} diff --git a/.github/workflows/cancel.yaml b/.github/workflows/cancel.yaml deleted file mode 100644 index 0abf01371..000000000 --- a/.github/workflows/cancel.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: Cancel -on: - workflow_run: - workflows: ["R-CMD-check", "Continuous Benchmarks (Comment)", "Continuous Benchmarks (Receive)", "pkgdown", "Commands", "test-coverage"] - types: - - requested -jobs: - cancel: - runs-on: ubuntu-latest - steps: - - uses: styfle/cancel-workflow-action@0.8.0 - with: - workflow_id: ${{ github.event.workflow.id }} diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 7dabe0282..39475147c 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -8,6 +8,11 @@ on: name: test-coverage +concurrency: + group: ${{ github.action }}-${{ github.event_path }} + cancel-in-progress: true + + jobs: test-coverage: runs-on: macOS-latest From 7b0b8aa5b585e8f43e0542bb02346db990dd4333 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Tue, 28 Dec 2021 23:26:07 +0100 Subject: [PATCH 114/114] test if in-flight is cancelled