Skip to content

Commit 8d23770

Browse files
committed
Address comments
1 parent d42a17a commit 8d23770

File tree

10 files changed

+36
-35
lines changed

10 files changed

+36
-35
lines changed

R/addins.R

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ style_active_file <- function() {
6868
} else if (is_r_file) {
6969
out <- try_transform_as_r_file(context, transformer)
7070
} else {
71-
abort("Can only style .R, .qmd, .Rmd, and .Rnw files.")
71+
abort("Can only style .qmd, .R, .Rmd, and .Rnw files.")
7272
}
7373
rstudioapi::modifyRange(
7474
c(1L, 1L, length(context$contents) + 1L, 1L),
@@ -97,11 +97,12 @@ save_after_styling_is_active <- function() {
9797
op_old <- as.logical(toupper(Sys.getenv("save_after_styling")))
9898
op_new <- getOption("styler.save_after_styling", default = "")
9999
if (!is.na(op_old)) {
100-
rlang::warn(paste(
101-
"Using the environment variable `save_after_styling` is deprecated and",
102-
"won't work in a future version of styler. Please use",
103-
"`options(styler.save_after_styling)` to control the behavior. If both are set,",
104-
"the R option is used."
100+
cli::cli_warn(c(
101+
"Using the environment variable {.envvar save_after_styling} is \\
102+
deprecated and won't work in a future version of styler. ",
103+
"!" = "Please use `options(styler.save_after_styling)` \\
104+
to control the behavior.",
105+
i = "If both are set, the R option is used."
105106
))
106107
}
107108

@@ -123,7 +124,7 @@ style_selection <- function() {
123124
communicate_addins_style_transformers()
124125
context <- get_rstudio_context()
125126
text <- context$selection[[1L]]$text
126-
if (all(nchar(text) == 0L)) abort("No code selected")
127+
if (!any(nzchar(text))) abort("No code selected")
127128
out <- style_text(
128129
text,
129130
transformers = get_addins_style_transformer(),
@@ -212,9 +213,9 @@ try_transform_as_r_file <- function(context, transformer) {
212213
transformer(context$contents),
213214
error = function(e) {
214215
preamble_for_unsaved <- paste(
215-
"Styling of unsaved files is only supported for R files with valid ",
216-
"code. Please save the file (as .R or .Rmd) and make sure that the R ",
217-
"code in it can be parsed. Then, try to style again."
216+
"Styling of unsaved files is only supported for R files with valid",
217+
"code. Please save the file (as .qmd, .R, or .Rmd) and make sure that",
218+
"the R code in it can be parsed. Then, try to style again."
218219
)
219220

220221
if (context$path == "") {

R/set-assert-args.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ assert_filetype <- function(lowercase_filetype) {
7373
allowed_types <- c("r", "rmd", "rmarkdown", "rnw", "rprofile", "qmd")
7474
if (!all(lowercase_filetype %in% allowed_types)) {
7575
abort(paste(
76-
"filetype must not contain other values than 'R', 'Rprofile',",
77-
"'Rmd', 'Rmarkdown', 'qmd' or 'Rnw' (case is ignored)."
76+
"filetype must not contain other values than 'qmd', 'R',",
77+
"'Rmarkdown', 'Rmd', 'Rnw', or 'Rprofile' (case is ignored)."
7878
))
7979
}
8080
}

R/style-guides.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,7 @@ tidyverse_reindention <- function() {
479479
#' @export
480480
scope_normalize <- function(scope, name = substitute(scope)) {
481481
levels <- c("none", "spaces", "indention", "line_breaks", "tokens")
482-
rlang::arg_match(
483-
scope,
484-
values = levels,
485-
multiple = TRUE
486-
)
482+
rlang::arg_match(scope, values = levels, multiple = TRUE)
487483

488484
if (inherits(scope, "AsIs")) {
489485
factor(as.character(scope), levels = levels, ordered = TRUE)

R/transform-code.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ transform_code <- function(path, fun, ..., dry) {
2222
..., dry = dry
2323
)
2424
} else {
25-
cli::cli_abort("{.path {path}} is not an R, Rmd, qmd, or Rnw file.")
25+
cli::cli_abort("{.path {path}} is not a qmd, R, Rmd, or Rnw file.")
2626
}
2727
}
2828

R/ui-styling.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ style_pkg <- function(pkg = ".",
8787
#' Prettify a package
8888
#'
8989
#' @param filetype Vector of file extensions indicating which file types should
90-
#' be styled. Case is ignored, and the `.` is optional, e.g. `c(".R",
91-
#' ".Rmd")`, or `c("r", "rmd")`. Supported values (after standardization) are:
92-
#' "r", "rprofile", "rmd", "rmarkdown", "rnw", "qmd". Rmarkdown is treated as
93-
#' Rmd.
90+
#' be styled. Case is ignored, and the `.` is optional, e.g. `c(".R",".Rmd")`,
91+
#' or `c("r", "rmd")`. Supported values (after standardization) are:
92+
#' "qmd", "r", "rmd", "rmarkdown", "rnw", and "rprofile".
93+
#' Rmarkdown is treated as Rmd.
9494
#' @param exclude_files Character vector with regular expressions to files
9595
#' that should be excluded from styling.
9696
#' @param exclude_dirs Character vector with directories to exclude

man/prettify_any.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.

man/prettify_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.

man/style_dir.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.

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.

vignettes/styler.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ styler::cache_deactivate()
2828

2929
styler provides the following API to format code:
3030

31-
- `style_file()` styles `.R`, `.qmd`, `.Rmd`, `.Rmarkdown`, `.Rnw`, and `.Rprofile` files.
31+
- `style_file()` styles `.qmd`, `.R`, `.Rmd`, `.Rmarkdown`, `.Rnw`, and `.Rprofile` files.
3232

3333
- `style_dir()` styles all these files in a directory.
3434

0 commit comments

Comments
 (0)