Skip to content

Commit 41af36c

Browse files
authored
Use air for formatting (#712)
1 parent 47dfdd1 commit 41af36c

Some content is hidden

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

87 files changed

+1316
-724
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
^CRAN-RELEASE$
1313
^revdep$
1414
^CRAN-SUBMISSION$
15+
^[\.]?air\.toml$
16+
^\.vscode$

.vscode/extensions.json

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

.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/content-type.R

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
#'
2222
#' # `types` can also specify multiple valid types
2323
#' resp_check_content_type(resp, c("application/xml", "application/json"))
24-
resp_check_content_type <- function(resp,
25-
valid_types = NULL,
26-
valid_suffix = NULL,
27-
check_type = TRUE,
28-
call = caller_env()) {
29-
24+
resp_check_content_type <- function(
25+
resp,
26+
valid_types = NULL,
27+
valid_suffix = NULL,
28+
check_type = TRUE,
29+
call = caller_env()
30+
) {
3031
check_response(resp)
3132
check_character(valid_types, allow_null = TRUE)
3233
check_string(valid_suffix, allow_null = TRUE)
@@ -89,11 +90,13 @@ parse_content_type <- function(x) {
8990
)
9091
}
9192

92-
check_content_type <- function(content_type,
93-
valid_types = NULL,
94-
valid_suffix = NULL,
95-
inform_check_type = FALSE,
96-
call = caller_env()) {
93+
check_content_type <- function(
94+
content_type,
95+
valid_types = NULL,
96+
valid_suffix = NULL,
97+
inform_check_type = FALSE,
98+
call = caller_env()
99+
) {
97100
parsed <- parse_content_type(content_type)
98101
base_type <- paste0(parsed$type, "/", parsed$subtype)
99102

R/curl.R

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ curl_translate <- function(cmd, simplify_headers = TRUE) {
5858
cookies <- data$headers$`Cookie`
5959
data$headers$`Cookie` <- NULL
6060
if (!is.null(cookies)) {
61-
steps <- add_curl_step(steps, "req_cookies_set", dots = cookies_parse(cookies))
61+
steps <- add_curl_step(
62+
steps,
63+
"req_cookies_set",
64+
dots = cookies_parse(cookies)
65+
)
6266
}
6367

6468
# Content type set with data
@@ -88,7 +92,12 @@ curl_translate <- function(cmd, simplify_headers = TRUE) {
8892
if (data$verbose) {
8993
perform_args$verbosity <- 1
9094
}
91-
steps <- add_curl_step(steps, "req_perform", main_args = perform_args, keep_if_empty = TRUE)
95+
steps <- add_curl_step(
96+
steps,
97+
"req_perform",
98+
main_args = perform_args,
99+
keep_if_empty = TRUE
100+
)
92101
out <- paste0(steps, collapse = paste0(pipe(), "\n "))
93102

94103
if (clip) {
@@ -280,11 +289,13 @@ quote_name <- function(x) {
280289
ifelse(is_syntactic(x), x, encodeString(x, quote = "`"))
281290
}
282291

283-
add_curl_step <- function(steps,
284-
f,
285-
main_args = NULL,
286-
dots = NULL,
287-
keep_if_empty = FALSE) {
292+
add_curl_step <- function(
293+
steps,
294+
f,
295+
main_args = NULL,
296+
dots = NULL,
297+
keep_if_empty = FALSE
298+
) {
288299
args <- c(main_args, dots)
289300

290301
if (is_empty(args) && !keep_if_empty) {

R/iterate-helpers.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@
5555
#' max_reqs = Inf
5656
#' )
5757
#' }
58-
iterate_with_offset <- function(param_name,
59-
start = 1,
60-
offset = 1,
61-
resp_pages = NULL,
62-
resp_complete = NULL) {
58+
iterate_with_offset <- function(
59+
param_name,
60+
start = 1,
61+
offset = 1,
62+
resp_pages = NULL,
63+
resp_complete = NULL
64+
) {
6365
check_string(param_name)
6466
check_number_whole(start)
6567
check_number_whole(offset, min = 1)

R/jwt.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@
2727
#' @examples
2828
#' claim <- jwt_claim()
2929
#' str(claim)
30-
jwt_claim <- function(iss = NULL,
31-
sub = NULL,
32-
aud = NULL,
33-
exp = unix_time() + 5L * 60L,
34-
nbf = unix_time(),
35-
iat = unix_time(),
36-
jti = NULL,
37-
...) {
30+
jwt_claim <- function(
31+
iss = NULL,
32+
sub = NULL,
33+
aud = NULL,
34+
exp = unix_time() + 5L * 60L,
35+
nbf = unix_time(),
36+
iat = unix_time(),
37+
jti = NULL,
38+
...
39+
) {
3840
# https://datatracker.ietf.org/doc/html/rfc7519
3941
jose::jwt_claim(
4042
iss = iss,

R/oauth-client.R

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@
4040
#' @examples
4141
#' oauth_client("myclient", "http://example.com/token_url", secret = "DONTLOOK")
4242
oauth_client <- function(
43-
id,
44-
token_url,
45-
secret = NULL,
46-
key = NULL,
47-
auth = c("body", "header", "jwt_sig"),
48-
auth_params = list(),
49-
name = hash(id)
50-
) {
51-
43+
id,
44+
token_url,
45+
secret = NULL,
46+
key = NULL,
47+
auth = c("body", "header", "jwt_sig"),
48+
auth_params = list(),
49+
name = hash(id)
50+
) {
5251
check_string(id)
5352
check_string(token_url)
5453
check_string(secret, allow_null = TRUE)
@@ -66,7 +65,9 @@ oauth_client <- function(
6665
cli::cli_abort("{.code auth = 'jwt_sig'} requires a {.arg key}.")
6766
}
6867
if (!has_name(auth_params, "claim")) {
69-
cli::cli_abort("{.code auth = 'jwt_sig'} requires a claim specification in {.arg auth_params}.")
68+
cli::cli_abort(
69+
"{.code auth = 'jwt_sig'} requires a claim specification in {.arg auth_params}."
70+
)
7071
}
7172
}
7273

@@ -167,7 +168,8 @@ oauth_client_req_auth <- function(req, client) {
167168
#' @export
168169
#' @rdname oauth_client_req_auth
169170
oauth_client_req_auth_header <- function(req, client) {
170-
req_auth_basic(req,
171+
req_auth_basic(
172+
req,
171173
username = client$id,
172174
password = unobfuscate(client$secret)
173175
)
@@ -176,7 +178,8 @@ oauth_client_req_auth_header <- function(req, client) {
176178
#' @export
177179
#' @rdname oauth_client_req_auth
178180
oauth_client_req_auth_body <- function(req, client) {
179-
req_body_form(req,
181+
req_body_form(
182+
req,
180183
client_id = client$id,
181184
client_secret = unobfuscate(client$secret) # might be NULL
182185
)
@@ -185,24 +188,33 @@ oauth_client_req_auth_body <- function(req, client) {
185188
#' @inheritParams jwt_claim
186189
#' @export
187190
#' @rdname oauth_client_req_auth
188-
oauth_client_req_auth_jwt_sig <- function(req, client, claim, size = 256, header = list()) {
191+
oauth_client_req_auth_jwt_sig <- function(
192+
req,
193+
client,
194+
claim,
195+
size = 256,
196+
header = list()
197+
) {
189198
claim <- exec("jwt_claim", !!!claim)
190199
jwt <- jwt_encode_sig(claim, key = client$key, size = size, header = header)
191200

192201
# https://datatracker.ietf.org/doc/html/rfc7523#section-2.2
193-
req_body_form(req,
202+
req_body_form(
203+
req,
194204
client_assertion = jwt,
195205
client_assertion_type = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
196206
)
197207
}
198208

199209
# Helpers -----------------------------------------------------------------
200210

201-
oauth_flow_check <- function(flow, client,
202-
is_confidential = FALSE,
203-
interactive = FALSE,
204-
error_call = caller_env()) {
205-
211+
oauth_flow_check <- function(
212+
flow,
213+
client,
214+
is_confidential = FALSE,
215+
interactive = FALSE,
216+
error_call = caller_env()
217+
) {
206218
if (!inherits(client, "httr2_oauth_client")) {
207219
cli::cli_abort(
208220
"{.arg client} must be an OAuth client created with {.fn oauth_client}.",
@@ -228,10 +240,12 @@ oauth_flow_check <- function(flow, client,
228240
}
229241
}
230242

231-
oauth_client_get_token <- function(client,
232-
grant_type,
233-
...,
234-
error_call = caller_env()) {
243+
oauth_client_get_token <- function(
244+
client,
245+
grant_type,
246+
...,
247+
error_call = caller_env()
248+
) {
235249
req <- request(client$token_url)
236250
req <- req_body_form(req, grant_type = grant_type, ...)
237251
req <- oauth_client_req_auth(req, client)

0 commit comments

Comments
 (0)