Skip to content

Commit a749d87

Browse files
Merge pull request #931 from r-lib/issue-931
support qmd file format, and treat it internally as R markdown
2 parents eec45e4 + 5df9c8a commit a749d87

26 files changed

+384
-14
lines changed

NEWS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
# styler 1.7.0.9000 (Development version)
2+
3+
**Features**
4+
5+
* `filetype` `.qmd` is now supported, but not turned on by default (#931).
16
* new R option `styler.ignore_alignment` controls if alignment should be
27
detected (and preserved) or not (#932).
8+
9+
**Bug Fixes**
10+
311
* the cache is also invalidated on changing the stylerignore markers (#932).
412

13+
514
# styler 1.7.0
615

716
* if `else` follows directly after `if`, line breaks are removed (#935).

R/addins.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ style_active_file <- function() {
6060
is_rprofile_file(context$path)
6161
)
6262

63-
if (is_rmd_file(context$path)) {
63+
if (is_rmd_file(context$path) || is_qmd_file(context$path)) {
6464
out <- transform_mixed(context$contents, transformer, filetype = "Rmd")
6565
} else if (is_rnw_file(context$path)) {
6666
out <- transform_mixed(context$contents, transformer, filetype = "Rnw")

R/set-assert-args.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ set_and_assert_arg_filetype <- function(filetype) {
7171
#' @importFrom rlang abort
7272
#' @keywords internal
7373
assert_filetype <- function(lowercase_filetype) {
74-
if (!all(lowercase_filetype %in% c("r", "rmd", "rmarkdown", "rnw", "rprofile"))) {
74+
allowed_types <- c("r", "rmd", "rmarkdown", "rnw", "rprofile", "qmd")
75+
if (!all(lowercase_filetype %in% allowed_types)) {
7576
abort(paste(
7677
"filetype must not contain other values than 'R', 'Rprofile',",
77-
"'Rmd', 'Rmarkdown' or 'Rnw' (case is ignored)."
78+
"'Rmd', 'Rmarkdown', 'qmd' or 'Rnw' (case is ignored)."
7879
))
7980
}
8081
}

R/transform-code.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
transform_code <- function(path, fun, ..., dry) {
1212
if (is_plain_r_file(path) || is_rprofile_file(path)) {
1313
transform_utf8(path, fun = fun, ..., dry = dry)
14-
} else if (is_rmd_file(path)) {
14+
} else if (is_rmd_file(path) || is_qmd_file(path)) {
1515
transform_utf8(path,
1616
fun = partial(transform_mixed, transformer_fun = fun, filetype = "Rmd"),
1717
..., dry = dry

R/ui-styling.R

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ NULL
77
#'
88
#' Performs various substitutions in all `.R` files in a package
99
#' (code and tests). One can also (optionally) style `.Rmd`, `.Rmarkdown` and/or
10-
#' `.Rnw` files (vignettes and readme) by changing the `filetype` argument.
10+
#' `.qmd`, `.Rnw` files (vignettes and readme) by changing the `filetype`
11+
#' argument.
1112
#' Carefully examine the results after running this function!
1213
#'
1314
#' @param pkg Path to a (subdirectory of an) R package.
@@ -161,6 +162,17 @@ prettify_pkg <- function(transformers,
161162
)
162163
)
163164
}
165+
166+
if ("\\.qmd" %in% filetype_) {
167+
vignette_files <- append(
168+
vignette_files,
169+
dir_without_.(
170+
path = ".",
171+
pattern = "\\.qmd$"
172+
)
173+
)
174+
}
175+
164176
files <- setdiff(
165177
c(r_files, rprofile_files, vignette_files, readme),
166178
exclude_files
@@ -214,7 +226,8 @@ style_text <- function(text,
214226

215227
#' Prettify arbitrary R code
216228
#'
217-
#' Performs various substitutions in all `.R`, `.Rmd`, `.Rmarkdown` and/or `.Rnw` files
229+
#' Performs various substitutions in all `.R`, `.Rmd`, `.Rmarkdown`, `qmd`
230+
#' and/or `.Rnw` files
218231
#' in a directory (by default only `.R` files are styled - see `filetype` argument).
219232
#' Carefully examine the results after running this function!
220233
#' @param path Path to a directory with files to transform.
@@ -263,8 +276,8 @@ style_dir <- function(path = ".",
263276
#'
264277
#' This is a helper function for style_dir.
265278
#' @inheritParams style_pkg
266-
#' @param recursive A logical value indicating whether or not files in subdirectories
267-
#' should be styled as well.
279+
#' @param recursive A logical value indicating whether or not files in
280+
#' subdirectories should be styled as well.
268281
#' @keywords internal
269282
prettify_any <- function(transformers,
270283
filetype,
@@ -298,7 +311,7 @@ prettify_any <- function(transformers,
298311
)
299312
}
300313

301-
#' Style `.R`, `.Rmd`, `.Rmarkdown` or `.Rnw` files
314+
#' Style `.R`, `.Rmd`, `.Rmarkdown`, `.qmd` or `.Rnw` files
302315
#'
303316
#' Performs various substitutions in the files specified.
304317
#' Carefully examine the results after running this function!

R/utils-files.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ is_rnw_file <- function(path) {
1313
grepl("\\.Rnw$", path, ignore.case = TRUE)
1414
}
1515

16+
is_qmd_file <- function(path) {
17+
grepl("\\.qmd$", path, ignore.case = TRUE)
18+
}
19+
20+
1621
is_unsaved_file <- function(path) {
1722
path == ""
1823
}

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

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

man/style_file.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/style_pkg.Rd

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

0 commit comments

Comments
 (0)