Skip to content

Commit

Permalink
exclude files is not interpreteted as a regex instead of plain file n…
Browse files Browse the repository at this point in the history
…ames and R/import-standalone.*\\.R is added
  • Loading branch information
lorenzwalthert committed Jul 16, 2023
1 parent 6d2f25d commit a2b8ad4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion API
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ specify_reindention(regex_pattern = NULL, indention = 0L, comments_only = TRUE)
specify_transformers_drop(spaces = NULL, indention = NULL, line_breaks = NULL, tokens = NULL)
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile", "Rmd", "Rmarkdown", "Rnw", "Qmd"), recursive = TRUE, exclude_files = NULL, exclude_dirs = c("packrat", "renv"), include_roxygen_examples = TRUE, base_indention = 0L, dry = "off")
style_file(path, ..., style = tidyverse_style, transformers = style(...), include_roxygen_examples = TRUE, base_indention = 0L, dry = "off")
style_pkg(pkg = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile", "Rmd", "Rmarkdown", "Rnw", "Qmd"), exclude_files = c("R/RcppExports.R", "R/cpp11.R", "R/import-standalone.+R"), exclude_dirs = c("packrat", "renv"), include_roxygen_examples = TRUE, base_indention = 0L, dry = "off")
style_pkg(pkg = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile", "Rmd", "Rmarkdown", "Rnw", "Qmd"), exclude_files = c("R/RcppExports\\.R", "R/cpp11\\.R", "R/import-standalone.*\\.R"), exclude_dirs = c("packrat", "renv"), include_roxygen_examples = TRUE, base_indention = 0L, dry = "off")
style_text(text, ..., style = tidyverse_style, transformers = style(...), include_roxygen_examples = TRUE, base_indention = 0L)
tidyverse_math_token_spacing()
tidyverse_reindention()
Expand Down
8 changes: 4 additions & 4 deletions R/ui-styling.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ style_pkg <- function(pkg = ".",
style = tidyverse_style,
transformers = style(...),
filetype = c("R", "Rprofile", "Rmd", "Rmarkdown", "Rnw", "Qmd"),
exclude_files = c("R/RcppExports.R", "R/cpp11.R", "R/import-standalone.+R"),
exclude_files = c("R/RcppExports\\.R", "R/cpp11\\.R", "R/import-standalone.*\\.R"),
exclude_dirs = c("packrat", "renv"),
include_roxygen_examples = TRUE,
base_indention = 0L,
Expand All @@ -91,7 +91,7 @@ style_pkg <- function(pkg = ".",
#' ".Rmd")`, or `c("r", "rmd")`. Supported values (after standardization) are:
#' "r", "rprofile", "rmd", "rmarkdown", "rnw", "qmd". Rmarkdown is treated as
#' Rmd.
#' @param exclude_files Character vector with paths or regular expressions to files
#' @param exclude_files Character vector with regular expressions to files
#' that should be excluded from styling.
#' @param exclude_dirs Character vector with directories to exclude
#' (recursively). Note that the default values were set for consistency with
Expand All @@ -107,6 +107,8 @@ prettify_pkg <- function(transformers,
dry) {
filetype_ <- set_and_assert_arg_filetype(filetype)
r_files <- rprofile_files <- vignette_files <- readme <- NULL
all_files <- list.files(".", recursive = TRUE, all.files = TRUE)
exclude_files <- grep(paste0(exclude_files, collapse = "|"), all_files, value = TRUE)
exclude_files <- set_arg_paths(exclude_files)
exclude_files_regex <- paste0(exclude_files[!file.exists(exclude_files)], collapse = "|")
exclude_files <- c(
Expand Down Expand Up @@ -173,8 +175,6 @@ prettify_pkg <- function(transformers,
c(r_files, rprofile_files, vignette_files, readme),
exclude_files
)
# Remove the regex.
files <- files[!grepl(exclude_files_regex, files)]
transform_files(files,
transformers = transformers,
include_roxygen_examples = include_roxygen_examples,
Expand Down
2 changes: 1 addition & 1 deletion man/prettify_any.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/prettify_pkg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/style_dir.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/style_pkg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions tests/testthat/test-public_api-0.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,26 @@ test_that("styler can style package and exclude some directories and files", {
capture_output(expect_true({
styled <- style_pkg(testthat_file("public-api", "xyzpackage"),
exclude_dirs = "tests",
exclude_files = ".Rprofile"
exclude_files = "\\.Rprofile"
)
nrow(styled) == 1
}))

capture_output(expect_true({
styled <- style_pkg(testthat_file("public-api", "xyzpackage"),
exclude_dirs = "tests",
exclude_files = "./.Rprofile"
exclude_files = ".*ofile"
)
nrow(styled) == 1
}))

capture_output(expect_true({
styled <- style_pkg(testthat_file("public-api", "xyzpackage"),
exclude_dirs = "tests",
exclude_files = "hello"
)
nrow(styled) == 0
}))
})


Expand Down

0 comments on commit a2b8ad4

Please sign in to comment.