Skip to content

Commit 12f7eb6

Browse files
Merge pull request #1138 from r-lib/standalone
Follow up: Standalone should not be styled #1135
2 parents 957d64f + 30e8f15 commit 12f7eb6

File tree

7 files changed

+29
-16
lines changed

7 files changed

+29
-16
lines changed

API

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ specify_reindention(regex_pattern = NULL, indention = 0L, comments_only = TRUE)
2727
specify_transformers_drop(spaces = NULL, indention = NULL, line_breaks = NULL, tokens = NULL)
2828
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")
2929
style_file(path, ..., style = tidyverse_style, transformers = style(...), include_roxygen_examples = TRUE, base_indention = 0L, dry = "off")
30-
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")
30+
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")
3131
style_text(text, ..., style = tidyverse_style, transformers = style(...), include_roxygen_examples = TRUE, base_indention = 0L)
3232
tidyverse_math_token_spacing()
3333
tidyverse_reindention()

R/ui-styling.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ style_pkg <- function(pkg = ".",
6969
style = tidyverse_style,
7070
transformers = style(...),
7171
filetype = c("R", "Rprofile", "Rmd", "Rmarkdown", "Rnw", "Qmd"),
72-
exclude_files = c("R/RcppExports.R", "R/cpp11.R"),
72+
exclude_files = c("R/RcppExports\\.R", "R/cpp11\\.R", "R/import-standalone.*\\.R"),
7373
exclude_dirs = c("packrat", "renv"),
7474
include_roxygen_examples = TRUE,
7575
base_indention = 0L,
@@ -91,8 +91,8 @@ style_pkg <- function(pkg = ".",
9191
#' ".Rmd")`, or `c("r", "rmd")`. Supported values (after standardization) are:
9292
#' "r", "rprofile", "rmd", "rmarkdown", "rnw", "qmd". Rmarkdown is treated as
9393
#' Rmd.
94-
#' @param exclude_files Character vector with paths to files that should be
95-
#' excluded from styling.
94+
#' @param exclude_files Character vector with regular expressions to files
95+
#' that should be excluded from styling.
9696
#' @param exclude_dirs Character vector with directories to exclude
9797
#' (recursively). Note that the default values were set for consistency with
9898
#' [style_dir()] and as these directories are anyways not styled.
@@ -107,8 +107,12 @@ prettify_pkg <- function(transformers,
107107
dry) {
108108
filetype_ <- set_and_assert_arg_filetype(filetype)
109109
r_files <- rprofile_files <- vignette_files <- readme <- NULL
110+
all_files <- list.files(".", recursive = TRUE, all.files = TRUE)
111+
exclude_files <- grep(paste0(exclude_files, collapse = "|"), all_files, value = TRUE)
112+
exclude_files <- set_arg_paths(exclude_files)
113+
exclude_files_regex <- paste0(exclude_files[!file.exists(exclude_files)], collapse = "|")
110114
exclude_files <- c(
111-
set_arg_paths(exclude_files),
115+
exclude_files,
112116
dir_without_.(exclude_dirs, pattern = map_filetype_to_pattern(filetype))
113117
)
114118
if ("\\.r" %in% filetype_) {

man/prettify_any.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/prettify_pkg.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/style_dir.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/style_pkg.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-public_api-0.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,26 @@ test_that("styler can style package and exclude some directories and files", {
3232
capture_output(expect_true({
3333
styled <- style_pkg(testthat_file("public-api", "xyzpackage"),
3434
exclude_dirs = "tests",
35-
exclude_files = ".Rprofile"
35+
exclude_files = "\\.Rprofile"
3636
)
3737
nrow(styled) == 1
3838
}))
3939

4040
capture_output(expect_true({
4141
styled <- style_pkg(testthat_file("public-api", "xyzpackage"),
4242
exclude_dirs = "tests",
43-
exclude_files = "./.Rprofile"
43+
exclude_files = ".*ofile"
4444
)
4545
nrow(styled) == 1
4646
}))
47+
48+
capture_output(expect_true({
49+
styled <- style_pkg(testthat_file("public-api", "xyzpackage"),
50+
exclude_dirs = "tests",
51+
exclude_files = "hello"
52+
)
53+
nrow(styled) == 0
54+
}))
4755
})
4856

4957

0 commit comments

Comments
 (0)