Skip to content

Commit

Permalink
Merge pull request #1138 from r-lib/standalone
Browse files Browse the repository at this point in the history
Follow up:  Standalone should not be styled #1135
  • Loading branch information
lorenzwalthert authored Sep 24, 2023
2 parents 957d64f + 30e8f15 commit 12f7eb6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 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"), 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
12 changes: 8 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"),
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,8 +91,8 @@ 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 to files that should be
#' excluded from styling.
#' @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
#' [style_dir()] and as these directories are anyways not styled.
Expand All @@ -107,8 +107,12 @@ 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(
set_arg_paths(exclude_files),
exclude_files,
dir_without_.(exclude_dirs, pattern = map_filetype_to_pattern(filetype))
)
if ("\\.r" %in% filetype_) {
Expand Down
4 changes: 2 additions & 2 deletions man/prettify_any.Rd

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

4 changes: 2 additions & 2 deletions man/prettify_pkg.Rd

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

4 changes: 2 additions & 2 deletions man/style_dir.Rd

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

7 changes: 4 additions & 3 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 12f7eb6

Please sign in to comment.