From 2702d1b37dda3a98a0dd964b644544e659b7aa61 Mon Sep 17 00:00:00 2001 From: Melissa Van Bussel Date: Fri, 19 Sep 2025 10:30:07 -0400 Subject: [PATCH] Add air formatter Fixes #70 --- .Rbuildignore | 1 + .vscode/settings.json | 4 ++++ R/git-auth.R | 36 +++++++++++++++++++++-------- R/list-creds.R | 28 ++++++++++++++++------ man/gitcreds-package.Rd | 2 +- tests/testthat/helper.R | 12 +++++++--- tests/testthat/test-gitcreds-list.R | 4 +++- tests/testthat/test-standalone.R | 4 +++- 8 files changed, 69 insertions(+), 22 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index fbfd4c2..ef045cd 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -13,3 +13,4 @@ ^LICENSE\.md$ ^[\.]?air\.toml$ ^\.vscode$ +^[.]?air[.]toml$ diff --git a/.vscode/settings.json b/.vscode/settings.json index f2d0b79..a9f69fe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,9 @@ "[r]": { "editor.formatOnSave": true, "editor.defaultFormatter": "Posit.air-vscode" + }, + "[quarto]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "quarto.quarto" } } diff --git a/R/git-auth.R b/R/git-auth.R index 99c4bbd..37c8d50 100644 --- a/R/git-auth.R +++ b/R/git-auth.R @@ -187,7 +187,9 @@ gitcreds <- local({ check_for_git() out <- git_run(c("config", "--get-all", "credential.helper")) clear <- rev(which(out == "")) - if (length(clear)) out <- out[-(1:clear[1])] + if (length(clear)) { + out <- out[-(1:clear[1])] + } out } @@ -228,7 +230,9 @@ gitcreds <- local({ } if (val == "FAIL" || grepl("^FAIL:", val)) { class <- strsplit(val, ":", fixed = TRUE)[[1]][2] - if (is.na(class)) class <- "gitcreds_no_credentials" + if (is.na(class)) { + class <- "gitcreds_no_credentials" + } throw(new_error(class)) } @@ -438,8 +442,12 @@ gitcreds <- local({ repeat { ch <- utils::menu(title = "-> What would you like to do?", choices) - if (ch == 1) return(FALSE) - if (ch == 2) return(TRUE) + if (ch == 1) { + return(FALSE) + } + if (ch == 2) { + return(TRUE) + } msg("\nCurrent password: ", current$password, "\n\n") } @@ -530,7 +538,9 @@ gitcreds <- local({ } gitcreds_username_for_url <- function(url) { - if (is.null(url)) return(NULL) + if (is.null(url)) { + return(NULL) + } tryCatch( git_run(c( "config", @@ -591,10 +601,14 @@ gitcreds <- local({ } new_error <- function(class, ..., message = "", call. = TRUE, domain = NULL) { - if (message == "") message <- gitcred_errors()[[class]] + if (message == "") { + message <- gitcred_errors()[[class]] + } message <- .makeMessage(message, domain = domain) cond <- list(message = message, ...) - if (call.) cond$call <- sys.call(-1) + if (call.) { + cond$call <- sys.call(-1) + } class(cond) <- c(class, "gitcreds_error", "error", "condition") cond } @@ -612,10 +626,14 @@ gitcreds <- local({ call. = TRUE, domain = NULL ) { - if (message == "") message <- gitcred_errors()[[class]] + if (message == "") { + message <- gitcred_errors()[[class]] + } message <- .makeMessage(message, domain = domain) cond <- list(message = message, ...) - if (call.) cond$call <- sys.call(-1) + if (call.) { + cond$call <- sys.call(-1) + } class(cond) <- c(class, "gitcreds_warning", "warning", "condition") cond } diff --git a/R/list-creds.R b/R/list-creds.R index 37356ed..da7e462 100644 --- a/R/list-creds.R +++ b/R/list-creds.R @@ -132,7 +132,9 @@ gitcreds_list <- function( host <- NULL if (!is.null(url)) { purl <- gitcreds$parse_url(url) - if (!is.na(purl$host)) host <- purl$host + if (!is.na(purl$host)) { + host <- purl$host + } if (!is.na(purl$protocol)) protocol <- purl$protocol } protocol <- protocol %||% "https" @@ -218,9 +220,15 @@ gitcreds_list_manager_core_macos <- function(url, host, protocol) { } is_manager_core_macos_item <- function(it, protocol, host) { - if (is.null(it$attributes$service)) return(FALSE) - if (!grepl("^git:", it$attributes$service)) return(FALSE) - if (is.null(host)) return(TRUE) + if (is.null(it$attributes$service)) { + return(FALSE) + } + if (!grepl("^git:", it$attributes$service)) { + return(FALSE) + } + if (is.null(host)) { + return(TRUE) + } iturl <- sub("^git:", "", it$attributes$service) piturl <- gitcreds$parse_url(iturl) !is.na(piturl$host) && @@ -245,10 +253,16 @@ gitcreds_list_manager_core_win <- function(url, host, protocol) { } is_manager_core_win_item <- function(it, protocol, host) { - if (it$type != "generic") return(FALSE) - if (!grepl("^git:", it$target_name)) return(FALSE) + if (it$type != "generic") { + return(FALSE) + } + if (!grepl("^git:", it$target_name)) { + return(FALSE) + } iturl <- sub("^git:", "", it$target_name) - if (is.null(host)) return(TRUE) + if (is.null(host)) { + return(TRUE) + } piturl <- gitcreds$parse_url(iturl) !is.na(piturl$host) && piturl$host == host && diff --git a/man/gitcreds-package.Rd b/man/gitcreds-package.Rd index 3d00162..0a7c522 100644 --- a/man/gitcreds-package.Rd +++ b/man/gitcreds-package.Rd @@ -21,7 +21,7 @@ Useful links: Other contributors: \itemize{ - \item Posit Software, PBC [copyright holder, funder] + \item Posit Software, PBC (03wc8by49) [copyright holder, funder] } } diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 1491b79..1dfdb8b 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -3,7 +3,9 @@ is_ci <- function() { } gc_test_that <- function(desc, code, os = NULL, helpers = NULL) { - if (!is_ci()) return() + if (!is_ci()) { + return() + } if (!is.null(os)) { if (!gitcreds$get_os() %in% os) return() } @@ -187,13 +189,17 @@ isFALSE <- function(x) { is_false_check_env_var <- function(x, default = "") { # like utils:::str2logical val <- Sys.getenv(x, default) - if (isFALSE(as.logical(val))) return(TRUE) + if (isFALSE(as.logical(val))) { + return(TRUE) + } tolower(val) %in% c("0", "no") } # Only skip if _R_CHECK_FORCE_SUGGESTS_ is false skip_if_not_installed <- function(pkg) { - if (!is_false_check_env_var("_R_CHECK_FORCE_SUGGESTS_")) return() + if (!is_false_check_env_var("_R_CHECK_FORCE_SUGGESTS_")) { + return() + } testthat::skip_if_not_installed(pkg) } diff --git a/tests/testthat/test-gitcreds-list.R b/tests/testthat/test-gitcreds-list.R index 41f2d11..278c408 100644 --- a/tests/testthat/test-gitcreds-list.R +++ b/tests/testthat/test-gitcreds-list.R @@ -171,7 +171,9 @@ gc_test_that( os = "windows", helper = "manager-core", { - if (packageVersion("oskeyring") <= "0.1.0") skip("Needs newer oskeyring") + if (packageVersion("oskeyring") <= "0.1.0") { + skip("Needs newer oskeyring") + } # needs oskeyring fun <- function() { diff --git a/tests/testthat/test-standalone.R b/tests/testthat/test-standalone.R index c21d7ec..3115f21 100644 --- a/tests/testthat/test-standalone.R +++ b/tests/testthat/test-standalone.R @@ -3,7 +3,9 @@ test_that("gitcreds is standalone", { objs <- ls(stenv, all.names = TRUE) funs <- Filter(function(x) is.function(stenv[[x]]), objs) funobjs <- mget(funs, stenv) - for (f in funobjs) expect_identical(environmentName(topenv(f)), "base") + for (f in funobjs) { + expect_identical(environmentName(topenv(f)), "base") + } skip_if_not_installed("codetools") expect_message(