Skip to content

Commit 9b70d4e

Browse files
authored
Format with autobracing version of Air (#1802)
* Format with autobracing active * Update snapshot test * Add in `fmt: skip` for sensitive deparse tests * Restore `handling-introspection.R` and `exclude` the `man/notes/` folder
1 parent bd757b6 commit 9b70d4e

17 files changed

+296
-100
lines changed

R/call.R

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -987,12 +987,18 @@ call_args_names <- function(call) {
987987
}
988988

989989
is_qualified_call <- function(x) {
990-
if (typeof(x) != "language") return(FALSE)
990+
if (typeof(x) != "language") {
991+
return(FALSE)
992+
}
991993
is_qualified_symbol(node_car(x))
992994
}
993995
is_namespaced_call <- function(x, ns = NULL, private = NULL) {
994-
if (typeof(x) != "language") return(FALSE)
995-
if (!is_namespaced_symbol(node_car(x), ns, private)) return(FALSE)
996+
if (typeof(x) != "language") {
997+
return(FALSE)
998+
}
999+
if (!is_namespaced_symbol(node_car(x), ns, private)) {
1000+
return(FALSE)
1001+
}
9961002
TRUE
9971003
}
9981004

@@ -1008,10 +1014,14 @@ call_unnamespace <- function(x) {
10081014

10091015
# Qualified and namespaced symbols are actually calls
10101016
is_qualified_symbol <- function(x) {
1011-
if (typeof(x) != "language") return(FALSE)
1017+
if (typeof(x) != "language") {
1018+
return(FALSE)
1019+
}
10121020

10131021
head <- node_cadr(node_cdr(x))
1014-
if (typeof(head) != "symbol") return(FALSE)
1022+
if (typeof(head) != "symbol") {
1023+
return(FALSE)
1024+
}
10151025

10161026
qualifier <- node_car(x)
10171027
identical(qualifier, namespace_sym) ||
@@ -1020,8 +1030,12 @@ is_qualified_symbol <- function(x) {
10201030
identical(qualifier, at_sym)
10211031
}
10221032
is_namespaced_symbol <- function(x, ns = NULL, private = NULL) {
1023-
if (typeof(x) != "language") return(FALSE)
1024-
if (!is_null(ns) && !identical(node_cadr(x), sym(ns))) return(FALSE)
1033+
if (typeof(x) != "language") {
1034+
return(FALSE)
1035+
}
1036+
if (!is_null(ns) && !identical(node_cadr(x), sym(ns))) {
1037+
return(FALSE)
1038+
}
10251039

10261040
head <- node_car(x)
10271041
if (is_null(private)) {

R/cnd.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,11 @@ cnd_format <- function(
574574
}
575575

576576
is_same_trace <- function() {
577-
compare <- if (is_null(pending_trace)) last_trace else
577+
compare <- if (is_null(pending_trace)) {
578+
last_trace
579+
} else {
578580
pending_trace[["trace"]]
581+
}
579582
if (!is_trace(trace) || !is_trace(compare)) {
580583
return(FALSE)
581584
}

R/standalone-cli.R

Lines changed: 145 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,24 @@
9191
#' functions apply default ANSI colours to these symbols if possible.
9292
#'
9393
#' @noRd
94-
symbol_info <- function() if (.rlang_cli_has_cli()) cli::symbol$info else "i"
95-
symbol_cross <- function() if (.rlang_cli_has_cli()) cli::symbol$cross else "x"
96-
symbol_tick <- function() if (.rlang_cli_has_cli()) cli::symbol$tick else "v"
97-
symbol_bullet <- function()
94+
symbol_info <- function() {
95+
if (.rlang_cli_has_cli()) cli::symbol$info else "i"
96+
}
97+
symbol_cross <- function() {
98+
if (.rlang_cli_has_cli()) cli::symbol$cross else "x"
99+
}
100+
symbol_tick <- function() {
101+
if (.rlang_cli_has_cli()) cli::symbol$tick else "v"
102+
}
103+
symbol_bullet <- function() {
98104
if (.rlang_cli_has_cli()) cli::symbol$bullet else "*"
99-
symbol_arrow <- function()
105+
}
106+
symbol_arrow <- function() {
100107
if (.rlang_cli_has_cli()) cli::symbol$arrow_right else ">"
101-
symbol_alert <- function() "!"
108+
}
109+
symbol_alert <- function() {
110+
"!"
111+
}
102112

103113
ansi_info <- function() col_blue(symbol_info())
104114
ansi_cross <- function() col_red(symbol_cross())
@@ -117,98 +127,167 @@ ansi_alert <- function() col_yellow(symbol_alert())
117127
#' @param x A string.
118128
#'
119129
#' @noRd
120-
col_black <- function(x)
130+
col_black <- function(x) {
121131
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::col_black(x)) else x
122-
col_blue <- function(x)
132+
}
133+
col_blue <- function(x) {
123134
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::col_blue(x)) else x
124-
col_cyan <- function(x)
135+
}
136+
col_cyan <- function(x) {
125137
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::col_cyan(x)) else x
126-
col_green <- function(x)
138+
}
139+
col_green <- function(x) {
127140
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::col_green(x)) else x
128-
col_magenta <- function(x)
141+
}
142+
col_magenta <- function(x) {
129143
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::col_magenta(x)) else x
130-
col_red <- function(x)
144+
}
145+
col_red <- function(x) {
131146
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::col_red(x)) else x
132-
col_white <- function(x)
147+
}
148+
col_white <- function(x) {
133149
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::col_white(x)) else x
134-
col_yellow <- function(x)
150+
}
151+
col_yellow <- function(x) {
135152
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::col_yellow(x)) else x
136-
col_grey <- function(x)
153+
}
154+
col_grey <- function(x) {
137155
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::col_grey(x)) else x
138-
col_silver <- function(x)
156+
}
157+
col_silver <- function(x) {
139158
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::col_silver(x)) else x
140-
col_none <- function(x)
159+
}
160+
col_none <- function(x) {
141161
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::col_none(x)) else x
162+
}
142163

143-
bg_black <- function(x)
164+
bg_black <- function(x) {
144165
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::bg_black(x)) else x
145-
bg_blue <- function(x)
166+
}
167+
bg_blue <- function(x) {
146168
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::bg_blue(x)) else x
147-
bg_cyan <- function(x)
169+
}
170+
bg_cyan <- function(x) {
148171
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::bg_cyan(x)) else x
149-
bg_green <- function(x)
172+
}
173+
bg_green <- function(x) {
150174
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::bg_green(x)) else x
151-
bg_magenta <- function(x)
175+
}
176+
bg_magenta <- function(x) {
152177
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::bg_magenta(x)) else x
153-
bg_red <- function(x)
178+
}
179+
bg_red <- function(x) {
154180
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::bg_red(x)) else x
155-
bg_white <- function(x)
181+
}
182+
bg_white <- function(x) {
156183
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::bg_white(x)) else x
157-
bg_yellow <- function(x)
184+
}
185+
bg_yellow <- function(x) {
158186
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::bg_yellow(x)) else x
159-
bg_none <- function(x)
187+
}
188+
bg_none <- function(x) {
160189
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::bg_none(x)) else x
190+
}
161191

162-
style_dim <- function(x)
192+
style_dim <- function(x) {
163193
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_dim(x)) else x
164-
style_blurred <- function(x)
194+
}
195+
style_blurred <- function(x) {
165196
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_blurred(x)) else x
166-
style_bold <- function(x)
197+
}
198+
style_bold <- function(x) {
167199
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_bold(x)) else x
168-
style_hidden <- function(x)
200+
}
201+
style_hidden <- function(x) {
169202
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_hidden(x)) else x
170-
style_inverse <- function(x)
203+
}
204+
style_inverse <- function(x) {
171205
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_inverse(x)) else x
172-
style_italic <- function(x)
206+
}
207+
style_italic <- function(x) {
173208
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_italic(x)) else x
174-
style_strikethrough <- function(x)
175-
if (.rlang_cli_has_cli())
176-
.rlang_cli_unstructure(cli::style_strikethrough(x)) else x
177-
style_underline <- function(x)
178-
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_underline(x)) else
209+
}
210+
style_strikethrough <- function(x) {
211+
if (.rlang_cli_has_cli()) {
212+
.rlang_cli_unstructure(cli::style_strikethrough(x))
213+
} else {
214+
x
215+
}
216+
}
217+
style_underline <- function(x) {
218+
if (.rlang_cli_has_cli()) {
219+
.rlang_cli_unstructure(cli::style_underline(x))
220+
} else {
179221
x
222+
}
223+
}
180224

181-
style_no_dim <- function(x)
225+
style_no_dim <- function(x) {
182226
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_no_dim(x)) else x
183-
style_no_blurred <- function(x)
184-
if (.rlang_cli_has_cli())
185-
.rlang_cli_unstructure(cli::style_no_blurred(x)) else x
186-
style_no_bold <- function(x)
227+
}
228+
style_no_blurred <- function(x) {
229+
if (.rlang_cli_has_cli()) {
230+
.rlang_cli_unstructure(cli::style_no_blurred(x))
231+
} else {
232+
x
233+
}
234+
}
235+
style_no_bold <- function(x) {
187236
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_no_bold(x)) else x
188-
style_no_hidden <- function(x)
189-
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_no_hidden(x)) else
237+
}
238+
style_no_hidden <- function(x) {
239+
if (.rlang_cli_has_cli()) {
240+
.rlang_cli_unstructure(cli::style_no_hidden(x))
241+
} else {
242+
x
243+
}
244+
}
245+
style_no_inverse <- function(x) {
246+
if (.rlang_cli_has_cli()) {
247+
.rlang_cli_unstructure(cli::style_no_inverse(x))
248+
} else {
249+
x
250+
}
251+
}
252+
style_no_italic <- function(x) {
253+
if (.rlang_cli_has_cli()) {
254+
.rlang_cli_unstructure(cli::style_no_italic(x))
255+
} else {
256+
x
257+
}
258+
}
259+
style_no_strikethrough <- function(x) {
260+
if (.rlang_cli_has_cli()) {
261+
.rlang_cli_unstructure(cli::style_no_strikethrough(x))
262+
} else {
190263
x
191-
style_no_inverse <- function(x)
192-
if (.rlang_cli_has_cli())
193-
.rlang_cli_unstructure(cli::style_no_inverse(x)) else x
194-
style_no_italic <- function(x)
195-
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_no_italic(x)) else
264+
}
265+
}
266+
style_no_underline <- function(x) {
267+
if (.rlang_cli_has_cli()) {
268+
.rlang_cli_unstructure(cli::style_no_underline(x))
269+
} else {
196270
x
197-
style_no_strikethrough <- function(x)
198-
if (.rlang_cli_has_cli())
199-
.rlang_cli_unstructure(cli::style_no_strikethrough(x)) else x
200-
style_no_underline <- function(x)
201-
if (.rlang_cli_has_cli())
202-
.rlang_cli_unstructure(cli::style_no_underline(x)) else x
203-
204-
style_reset <- function(x)
271+
}
272+
}
273+
274+
style_reset <- function(x) {
205275
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_reset(x)) else x
206-
style_no_colour <- function(x)
207-
if (.rlang_cli_has_cli()) .rlang_cli_unstructure(cli::style_no_color(x)) else
276+
}
277+
style_no_colour <- function(x) {
278+
if (.rlang_cli_has_cli()) {
279+
.rlang_cli_unstructure(cli::style_no_color(x))
280+
} else {
281+
x
282+
}
283+
}
284+
style_no_bg_colour <- function(x) {
285+
if (.rlang_cli_has_cli()) {
286+
.rlang_cli_unstructure(cli::style_no_bg_color(x))
287+
} else {
208288
x
209-
style_no_bg_colour <- function(x)
210-
if (.rlang_cli_has_cli())
211-
.rlang_cli_unstructure(cli::style_no_bg_color(x)) else x
289+
}
290+
}
212291

213292
CLI_SUPPORT_HYPERLINK <- "2.2.0"
214293
CLI_SUPPORT_HYPERLINK_PARAMS <- "3.1.1"
@@ -289,10 +368,12 @@ format_url <- function(x) .rlang_cli_format_inline(x, "url", "<%s>")
289368
format_var <- function(x) .rlang_cli_format_inline(x, "var", "`%s`")
290369
format_envvar <- function(x) .rlang_cli_format_inline(x, "envvar", "`%s`")
291370
format_field <- function(x) .rlang_cli_format_inline(x, "field", NULL)
292-
format_href <- function(x, target = NULL)
371+
format_href <- function(x, target = NULL) {
293372
.rlang_cli_format_inline_link(x, target, "href", "<%s>")
294-
format_run <- function(x, target = NULL)
373+
}
374+
format_run <- function(x, target = NULL) {
295375
.rlang_cli_format_inline_link(x, target, "run", "`%s`")
376+
}
296377

297378
format_error_arg_highlight <- function(x, quote = TRUE) {
298379
if (is_true(peek_option("rlang:::trace_test_highlight"))) {

R/standalone-lazyeval.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ warn_text_se <- function() {
2424
}
2525

2626
compat_lazy <- function(lazy, env = caller_env(), warn = TRUE) {
27-
if (warn) warn_underscored()
27+
if (warn) {
28+
warn_underscored()
29+
}
2830

2931
if (missing(lazy)) {
3032
return(quo())
@@ -41,7 +43,9 @@ compat_lazy <- function(lazy, env = caller_env(), warn = TRUE) {
4143
symbol = ,
4244
language = new_quosure(lazy, env),
4345
character = {
44-
if (warn) warn_text_se()
46+
if (warn) {
47+
warn_text_se()
48+
}
4549
parse_quo(lazy[[1]], env)
4650
},
4751
logical = ,

R/utils-cli-tree.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ cli_is_utf8_output <- function() {
139139
}
140140

141141
cli_is_latex_output <- function() {
142-
if (!("knitr" %in% loadedNamespaces())) return(FALSE)
142+
if (!("knitr" %in% loadedNamespaces())) {
143+
return(FALSE)
144+
}
143145
get("is_latex_output", asNamespace("knitr"))()
144146
}

air.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[format]
2+
exclude = ["man/notes/"]

tests/testthat/_snaps/current/cnd-abort.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,12 @@
176176
16. \-base::stop("bar")
177177
Code
178178
# Wrapped handler
179-
handler1 <- (function(cnd, call = caller_env()) handler2(cnd, call))
180-
handler2 <- (function(cnd, call) abort(cnd_header(cnd), parent = NA, call = call))
179+
handler1 <- (function(cnd, call = caller_env()) {
180+
handler2(cnd, call)
181+
})
182+
handler2 <- (function(cnd, call) {
183+
abort(cnd_header(cnd), parent = NA, call = call)
184+
})
181185
hh <- (function() {
182186
withCallingHandlers(foo(), error = function(cnd) handler1(cnd))
183187
})

0 commit comments

Comments
 (0)