Skip to content

Commit 3245437

Browse files
style: reformat with air (#2865)
`usethis::use_air()` and skips for readability
1 parent 7cf401f commit 3245437

106 files changed

Lines changed: 2701 additions & 1345 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@
2424
^vignettes/articles/\.quarto$
2525
^vignettes/articles/*_files$
2626
^vignettes/articles$
27+
^\.vscode$
28+
^[\.]?air\.toml$

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"Posit.air-vscode"
4+
]
5+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[r]": {
3+
"editor.formatOnSave": true,
4+
"editor.defaultFormatter": "Posit.air-vscode"
5+
}
6+
}

R/build-404.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ build_404 <- function(pkg = ".") {
66

77
if (!file_exists(page_md)) {
88
render_page(
9-
pkg, "title-body",
9+
pkg,
10+
"title-body",
1011
data = list(
1112
pagetitle = tr_("Page not found (404)"),
1213
body = tr_("Content not found. Please use links in the navbar.")
1314
),
1415
path = "404.html"
1516
)
16-
update_html(path_abs("404.html", start = pkg$dst_path), tweak_link_absolute, pkg = pkg)
17+
update_html(
18+
path_abs("404.html", start = pkg$dst_path),
19+
tweak_link_absolute,
20+
pkg = pkg
21+
)
1722
}
1823

1924
invisible()

R/build-article.R

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
#' `TRUE`, ensures that every article is build in a fresh environment, but
88
#' you may want to set it to `FALSE` to make debugging easier.
99
#' @param pandoc_args Pass additional arguments to pandoc. Used for testing.
10-
build_article <- function(name,
11-
pkg = ".",
12-
lazy = FALSE,
13-
seed = 1014L,
14-
new_process = TRUE,
15-
pandoc_args = character(),
16-
override = list(),
17-
quiet = TRUE) {
10+
build_article <- function(
11+
name,
12+
pkg = ".",
13+
lazy = FALSE,
14+
seed = 1014L,
15+
new_process = TRUE,
16+
pandoc_args = character(),
17+
override = list(),
18+
quiet = TRUE
19+
) {
1820
pkg <- section_init(pkg, "articles", override = override)
1921

2022
# Look up in pkg vignette data - this allows convenient automatic
@@ -49,35 +51,47 @@ build_article <- function(name,
4951
new_process = new_process,
5052
pandoc_args = pandoc_args,
5153
quiet = quiet
52-
)
54+
)
5355
} else {
5456
build_quarto_articles(pkg = pkg, article = name, quiet = quiet)
5557
}
5658
}
5759

58-
build_rmarkdown_article <- function(pkg,
59-
input_file,
60-
input_path,
61-
output_file,
62-
output_path,
63-
depth,
64-
seed = NULL,
65-
new_process = TRUE,
66-
pandoc_args = character(),
67-
quiet = TRUE,
68-
call = caller_env() ) {
60+
build_rmarkdown_article <- function(
61+
pkg,
62+
input_file,
63+
input_path,
64+
output_file,
65+
output_path,
66+
depth,
67+
seed = NULL,
68+
new_process = TRUE,
69+
pandoc_args = character(),
70+
quiet = TRUE,
71+
call = caller_env()
72+
) {
6973
cli::cli_inform("Reading {src_path(input_file)}")
7074
digest <- file_digest(output_path)
7175

7276
data <- data_article(pkg, input_file, call = call)
7377
if (data$as_is) {
7478
if (identical(data$ext, "html")) {
75-
setup <- rmarkdown_setup_custom(pkg, input_path, depth = depth, data = data)
79+
setup <- rmarkdown_setup_custom(
80+
pkg,
81+
input_path,
82+
depth = depth,
83+
data = data
84+
)
7685
} else {
7786
setup <- list(format = NULL, options = NULL)
7887
}
7988
} else {
80-
setup <- rmarkdown_setup_pkgdown(pkg, depth = depth, data = data, pandoc_args = pandoc_args)
89+
setup <- rmarkdown_setup_pkgdown(
90+
pkg,
91+
depth = depth,
92+
data = data,
93+
pandoc_args = pandoc_args
94+
)
8195
}
8296

8397
local_envvar_pkgdown(pkg)
@@ -127,7 +141,6 @@ build_rmarkdown_article <- function(pkg,
127141
}
128142

129143
invisible(path)
130-
131144
}
132145

133146

@@ -136,7 +149,7 @@ data_article <- function(pkg, input, call = caller_env()) {
136149

137150
opengraph <- check_open_graph(pkg, yaml$opengraph, input, call = call)
138151
opengraph$description <- opengraph$description %||% yaml$description
139-
152+
140153
list(
141154
opengraph = opengraph,
142155
pagetitle = escape_html(yaml$title),
@@ -148,19 +161,21 @@ data_article <- function(pkg, input, call = caller_env()) {
148161
)
149162
}
150163

151-
rmarkdown_setup_custom <- function(pkg,
152-
input_path,
153-
depth = 1L,
154-
data = list(),
155-
env = caller_env()) {
164+
rmarkdown_setup_custom <- function(
165+
pkg,
166+
input_path,
167+
depth = 1L,
168+
data = list(),
169+
env = caller_env()
170+
) {
156171
template <- rmarkdown_template(pkg, depth = depth, data = data, env = env)
157172

158173
# Override defaults & values supplied in metadata
159174
options <- list(
160175
template = template,
161176
self_contained = FALSE
162177
)
163-
178+
164179
output <- rmarkdown::default_output_format(input_path)
165180
if (output$name != "rmarkdown::html_vignette") {
166181
# Force to NULL unless overridden by user
@@ -170,12 +185,13 @@ rmarkdown_setup_custom <- function(pkg,
170185
list(format = NULL, options = options)
171186
}
172187

173-
rmarkdown_setup_pkgdown <- function(pkg,
174-
depth = 1L,
175-
data = list(),
176-
pandoc_args = character(),
177-
env = caller_env()) {
178-
188+
rmarkdown_setup_pkgdown <- function(
189+
pkg,
190+
depth = 1L,
191+
data = list(),
192+
pandoc_args = character(),
193+
env = caller_env()
194+
) {
179195
template <- rmarkdown_template(pkg, depth = depth, data = data, env = env)
180196

181197
format <- rmarkdown::html_document(
@@ -187,7 +203,10 @@ rmarkdown_setup_pkgdown <- function(pkg,
187203
extra_dependencies = bs_theme_deps_suppress(),
188204
pandoc_args = pandoc_args
189205
)
190-
format$knitr$opts_chunk <- fig_opts_chunk(pkg$figures, format$knitr$opts_chunk)
206+
format$knitr$opts_chunk <- fig_opts_chunk(
207+
pkg$figures,
208+
format$knitr$opts_chunk
209+
)
191210

192211
width <- config_pluck_number_whole(pkg, "code.width", default = 80)
193212
old_pre <- format$pre_knit
@@ -202,7 +221,12 @@ rmarkdown_setup_pkgdown <- function(pkg,
202221
}
203222

204223
# Generates pandoc template by rendering templates/content-article.html
205-
rmarkdown_template <- function(pkg, data = list(), depth = 1L, env = caller_env()) {
224+
rmarkdown_template <- function(
225+
pkg,
226+
data = list(),
227+
depth = 1L,
228+
env = caller_env()
229+
) {
206230
path <- withr::local_tempfile(
207231
pattern = "pkgdown-rmd-template-",
208232
fileext = ".html",

R/build-articles.R

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@
9292
#' in the articles index. You can suppress such warnings by listing the
9393
#' affected articles in a section with `title: internal` (case sensitive);
9494
#' this section will not be displayed on the index page.
95-
#'
95+
#'
9696
#' ## External articles
9797
#'
98-
#' You can link to arbitrary additional articles by adding an
98+
#' You can link to arbitrary additional articles by adding an
9999
#' `external-articles` entry to `_pkgdown.yml`. It should contain an array
100-
#' of objects with fields `name`, `title`, `href`, and `description`.
100+
#' of objects with fields `name`, `title`, `href`, and `description`.
101101
#'
102102
#' ```yaml
103103
#' external-articles:
@@ -106,7 +106,7 @@
106106
#' description: Improve model performance in imbalanced data sets through undersampling or oversampling.
107107
#' href: https://www.tidymodels.org/learn/models/sub-sampling/
108108
#' ```
109-
#'
109+
#'
110110
#' If you've defined a custom articles index, you'll need to include the name
111111
#' in one of the `contents` fields.
112112
#'
@@ -193,12 +193,14 @@
193193
#' freshly generated section in browser.
194194
#' @export
195195
#' @order 1
196-
build_articles <- function(pkg = ".",
197-
quiet = TRUE,
198-
lazy = TRUE,
199-
seed = 1014L,
200-
override = list(),
201-
preview = FALSE) {
196+
build_articles <- function(
197+
pkg = ".",
198+
quiet = TRUE,
199+
lazy = TRUE,
200+
seed = 1014L,
201+
override = list(),
202+
preview = FALSE
203+
) {
202204
pkg <- section_init(pkg, "articles", override = override)
203205
check_bool(quiet)
204206
check_bool(lazy)
@@ -297,7 +299,11 @@ data_articles <- function(pkg = ".", is_index = FALSE, call = caller_env()) {
297299
external <- config_pluck_external_articles(pkg, call = call)
298300
articles <- rbind(internal, external)
299301

300-
articles$description <- lapply(articles$description, markdown_text_block, pkg = pkg)
302+
articles$description <- lapply(
303+
articles$description,
304+
markdown_text_block,
305+
pkg = pkg
306+
)
301307

302308
# Hack data structure so we can use select_topics()
303309
articles$alias <- as.list(articles$name)
@@ -359,7 +365,13 @@ config_pluck_external_articles <- function(pkg, call = caller_env()) {
359365
)
360366
}
361367

362-
data_articles_index_section <- function(section, index, articles, pkg, call = caller_env()) {
368+
data_articles_index_section <- function(
369+
section,
370+
index,
371+
articles,
372+
pkg,
373+
call = caller_env()
374+
) {
363375
config_check_list(
364376
section,
365377
error_path = paste0("articles[", index, "]"),

R/build-favicons.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,21 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
8787
resp <- httr2::req_perform(req, tmp)
8888

8989
withCallingHandlers(
90-
paths <- utils::unzip(tmp, exdir = path(pkg$src_path, "pkgdown", "favicon")),
90+
paths <- utils::unzip(
91+
tmp,
92+
exdir = path(pkg$src_path, "pkgdown", "favicon")
93+
),
9194
warning = function(e) {
92-
cli::cli_abort("Your logo file couldn't be processed and may be corrupt.", parent = e)
95+
cli::cli_abort(
96+
"Your logo file couldn't be processed and may be corrupt.",
97+
parent = e
98+
)
9399
},
94100
error = function(e) {
95-
cli::cli_abort("Your logo file couldn't be processed and may be corrupt.", parent = e)
101+
cli::cli_abort(
102+
"Your logo file couldn't be processed and may be corrupt.",
103+
parent = e
104+
)
96105
}
97106
)
98107
cli::cli_inform(c("v" = "Added {.path {sort(path_file(paths))}}."))

R/build-footer.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ data_footer <- function(pkg = ".", call = caller_env()) {
33

44
config_pluck_list(pkg, "footer", call = call)
55
meta_components <- config_pluck_list(pkg, "footer.components", call = call)
6-
components <- modify_list(footnote_components(pkg, call = call), meta_components)
6+
components <- modify_list(
7+
footnote_components(pkg, call = call),
8+
meta_components
9+
)
710

811
meta_structure <- config_pluck_list(pkg, "footer.structure", call = call)
912
structure <- modify_list(footnote_structure(), meta_structure)
1013

11-
left <- markdown_text_block(pkg, paste0(components[structure$left], collapse = " "))
12-
right <- markdown_text_block(pkg, paste0(components[structure$right], collapse = " "))
14+
left <- markdown_text_block(
15+
pkg,
16+
paste0(components[structure$left], collapse = " ")
17+
)
18+
right <- markdown_text_block(
19+
pkg,
20+
paste0(components[structure$right], collapse = " ")
21+
)
1322

1423
list(left = left, right = right)
1524
}

R/build-github.R

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@
1616
#' @inheritParams deploy_to_branch
1717
#' @param dest_dir Directory to build site in.
1818
#' @export
19-
build_site_github_pages <- function(pkg = ".",
20-
...,
21-
dest_dir = "docs",
22-
clean = TRUE,
23-
install = FALSE,
24-
new_process = FALSE) {
25-
pkg <- as_pkgdown(pkg, override = list(destination = dest_dir))
19+
build_site_github_pages <- function(
20+
pkg = ".",
21+
...,
22+
dest_dir = "docs",
23+
clean = TRUE,
24+
install = FALSE,
25+
new_process = FALSE
26+
) {
27+
pkg <- as_pkgdown(pkg, override = list(destination = dest_dir))
2628

2729
if (clean) {
2830
cli::cli_rule("Cleaning files from old site")
2931
clean_site(pkg)
3032
}
3133

32-
build_site(pkg, preview = FALSE, install = install, new_process = new_process, ...)
34+
build_site(
35+
pkg,
36+
preview = FALSE,
37+
install = install,
38+
new_process = new_process,
39+
...
40+
)
3341
build_github_pages(pkg)
3442

3543
invisible()
@@ -53,12 +61,10 @@ build_github_pages <- function(pkg = ".") {
5361
}
5462

5563
cname_url <- function(url) {
56-
if (is.null(url))
57-
return(NULL)
64+
if (is.null(url)) return(NULL)
5865

5966
pieces <- xml2::url_parse(url)
60-
if (!pieces$path %in% c("", "/"))
61-
return(NULL)
67+
if (!pieces$path %in% c("", "/")) return(NULL)
6268

6369
pieces$server
6470
}

0 commit comments

Comments
 (0)