From 7283d018dedbfdfb30450b536160ec55ddb3c176 Mon Sep 17 00:00:00 2001 From: Fran Barton Date: Fri, 19 Dec 2025 23:16:18 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=99=20Add=20.lintr=20and=20appease=20l?= =?UTF-8?q?intr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .lintr | 2 ++ R/azkit_helpers.R | 2 +- R/get_container.R | 2 +- R/list_files.R | 10 +++++----- tests/testthat/test-azkit_helpers.R | 2 +- tests/testthat/test-read_azure_files.R | 6 ------ 6 files changed, 10 insertions(+), 14 deletions(-) create mode 100644 .lintr diff --git a/.lintr b/.lintr new file mode 100644 index 0000000..b08f4e1 --- /dev/null +++ b/.lintr @@ -0,0 +1,2 @@ +linters: linters_with_defaults() # see vignette("lintr") +encoding: "UTF-8" diff --git a/R/azkit_helpers.R b/R/azkit_helpers.R index 84e21cd..4f35257 100644 --- a/R/azkit_helpers.R +++ b/R/azkit_helpers.R @@ -108,7 +108,7 @@ check_container_class <- function(container) { if (inherits(container, "blob_container")) { container } else { - ccc <- "check_container_class" + ccc <- "check_container_class" # nolint cc <- rlang::caller_call() cli::cli_abort("{.fn {ccc}}: This is not a valid blob container", call = cc) } diff --git a/R/get_container.R b/R/get_container.R index 7bbbd56..caaccf3 100644 --- a/R/get_container.R +++ b/R/get_container.R @@ -31,7 +31,7 @@ get_container <- function(container_name = NULL, ...) { list_container_names <- function(token = NULL, ...) { token <- token %||% get_auth_token(...) endpoint <- get_default_endpoint(token) - lcn <- "list_container_names" + lcn <- "list_container_names" # nolint container_list <- AzureStor::list_blob_containers(endpoint) |> rlang::try_fetch(error = \(e) cli::cli_abort("Error in {.fn {lcn}}: {e}")) stopifnot("no containers found" = length(container_list) >= 1L) diff --git a/R/list_files.R b/R/list_files.R index bbb889d..a33ed39 100644 --- a/R/list_files.R +++ b/R/list_files.R @@ -36,7 +36,7 @@ list_files <- function(container, path = "", ext = "", recursive = TRUE) { tbl <- AzureStor::list_blobs(container, path, recursive = recursive) if (nrow(tbl) > 0) { - ext_rx <- if (nzchar(ext)) sub("^\\.+", "", ext) else ".*" + ext_rx <- if (nzchar(ext)) sub("^\\.+", "", ext) else ".*" # nolint tbl <- tbl |> dplyr::filter(!.data[["isdir"]] & gregg(.data[["name"]], "\\.{ext_rx}$")) } @@ -44,11 +44,11 @@ list_files <- function(container, path = "", ext = "", recursive = TRUE) { # A zero-row tbl can result if `path` is initially empty, or via the filter # step above. We handle this the same way, no matter which route led here. if (nrow(tbl) == 0) { + fix_path <- \(p) sub("^/+$", "", sub("^([^/])(.*)", "/\\1\\2", p)) # nolint + ext <- if (nzchar(ext)) paste0(" ", ext) + msg <- "No{ext} files found in {.val [{container$name}]:{fix_path(path)}}" if (rlang::is_interactive()) { - ext <- if (nzchar(ext)) paste0(" ", ext) - fix_path <- \(path) sub("^/+$", "", sub("^([^/])(.*)", "/\\1\\2", path)) - "No{ext} files found in {.val [{container[['name']]}]{fix_path(path)}}" |> - cli::cli_alert_info() + cli::cli_alert_info(msg) } invisible(character(0)) } else { diff --git a/tests/testthat/test-azkit_helpers.R b/tests/testthat/test-azkit_helpers.R index 9c34bd5..e336d89 100644 --- a/tests/testthat/test-azkit_helpers.R +++ b/tests/testthat/test-azkit_helpers.R @@ -15,7 +15,7 @@ test_that("I understand how rlang::abort works", { var <- "test" message <- "{.var {var}} error" # will only succeed if devtools::load_all() has been run: - # expect_error(rlang::abort(message), "`test` error") + # expect_error(rlang::abort(message), "`test` error") # nolint expect_error(rlang::abort(message), class = "rlang_error") rlang::local_use_cli(inline = TRUE) expect_error(rlang::abort(message), "`test` error", class = "rlang_error") diff --git a/tests/testthat/test-read_azure_files.R b/tests/testthat/test-read_azure_files.R index 956033c..f8ffa6b 100644 --- a/tests/testthat/test-read_azure_files.R +++ b/tests/testthat/test-read_azure_files.R @@ -182,9 +182,6 @@ test_that("dirname and basename logic works", { filepath_out <- AzureStor::list_blobs(res, path, recursive = FALSE) |> dplyr::filter( !dplyr::if_any("isdir") & - # Don't include `filepath` in the first regex here, because we want to - # filter to `file_ext` explicitly, as well as also allow for `filepath` - # to include its file extension if that suits the user's approach. dplyr::if_any("name", \(x) { gregg(x, "\\.{file_ext}$") & gregg(x, "^{filepath}") }) @@ -211,9 +208,6 @@ test_that("tdd of check_blob_exists", { dplyr::filter( !dplyr::if_any("isdir") & dplyr::if_any("name", \(x) { - # Don't include `file` in the regex here, because we want to filter to - # `file_ext` explicitly, as well as also allow for `file` to include - # its file extension if that suits the user's approach. grepl(glue::glue("\\.{file_ext}$"), x) & grepl(file, x) }) ) |>