From b4297ef3e170ea66f2ba6c543b662e95f104ef57 Mon Sep 17 00:00:00 2001 From: mpadge Date: Tue, 27 Aug 2024 10:22:04 +0200 Subject: [PATCH] reduce tag-specific 'process' fns to one generic fn for #41 --- DESCRIPTION | 2 +- R/roclet.R | 82 ++++++++------------------------------------------- codemeta.json | 2 +- 3 files changed, 14 insertions(+), 72 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1db6f07..b4da955 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: srr Title: 'rOpenSci' Review Roclets -Version: 0.1.3.008 +Version: 0.1.3.009 Authors@R: person("Mark", "Padgham", , "mark@ropensci.org", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/roclet.R b/R/roclet.R index 92ee318..ab7c4ed 100644 --- a/R/roclet.R +++ b/R/roclet.R @@ -153,14 +153,14 @@ get_verbose_flag <- function (blocks) { parse_one_msg_list <- function (msgs, block, tag, fn_name = TRUE, dir = "R") { if (length (roxygen2::block_get_tags (block, tag)) > 0L) { - call_fn <- paste0 ("process_", tag, "_tags") msgs <- c ( msgs, - do.call (call_fn, list ( + process_srrstats_tags ( + tag = tag, block = block, fn_name = fn_name, dir = dir - )) + ) ) } @@ -222,23 +222,24 @@ check_block_title <- function (block, tag) { #' #' @param fn_name Include name of calling function in message? #' @noRd -process_srrstats_tags <- function (block, fn_name = TRUE, dir = "R") { +process_srrstats_tags <- function (tag = "srrstats", block, + fn_name = TRUE, dir = "R") { - check_block_title (block, "srrstats") + check_block_title (block, tag) - func_name <- block$object$alias - - standards <- roxygen2::block_get_tags (block, "srrstats") + standards <- roxygen2::block_get_tags (block, tag) standards <- unlist (lapply (standards, function (i) i$val)) - snum <- extract_standard_numbers (standards) block_backref <- get_block_backref (block) block_line <- block$line msg <- paste0 ("[", paste0 (snum, collapse = ", "), "]") - if (fn_name && !is.null (func_name)) { - msg <- paste0 (msg, " in function '", func_name, "()'") + if (fn_name) { + func_name <- block$object$alias + if (!is.null (func_name)) { + msg <- paste0 (msg, " in function '", func_name, "()'") + } } ptn <- paste0 ("^.*", dir, "\\/") fpath <- regmatches (block$file, regexpr (ptn, block$file)) @@ -254,65 +255,6 @@ process_srrstats_tags <- function (block, fn_name = TRUE, dir = "R") { return (msg) } -#' process_srrstats_NA_tags -#' -#' @param fn_name Just a dummy here to allow do.call -#' @noRd -process_srrstatsNA_tags <- function (block, fn_name = TRUE, dir = "R") { # nolint - - check_block_title (block, "srrstatsNA") - - standards <- roxygen2::block_get_tags (block, "srrstatsNA") - standards <- unlist (lapply (standards, function (i) i$val)) - snum <- extract_standard_numbers (standards) - - block_backref <- get_block_backref (block) - block_line <- block$line - - ptn <- paste0 ("^.*", dir, "\\/") - fpath <- regmatches (block$file, regexpr (ptn, block$file)) - fpath_full <- gsub (fpath, paste0 (dir, "/"), block$file) - - msg <- paste0 ( - "[", paste0 (snum, collapse = ", "), - "] on line#", block_line, - " of file [", - fpath_full, - "]" - ) - - return (msg) -} - -#' process_srrstats_TODO_tags -#' -#' @param fn_name Just a dummy here to allow do.call -#' @noRd -process_srrstatsTODO_tags <- function (block, fn_name = TRUE, dir = "R") { # nolint - - check_block_title (block, "srrstatsTODO") - - standards <- roxygen2::block_get_tags (block, "srrstatsTODO") - standards <- unlist (lapply (standards, function (i) i$val)) - snum <- extract_standard_numbers (standards) - - block_backref <- get_block_backref (block) - block_line <- block$line - - ptn <- paste0 ("^.*", dir, "\\/") - fpath <- regmatches (block$file, regexpr (ptn, block$file)) - fpath_full <- gsub (fpath, paste0 (dir, "/"), block$file) - - msg <- paste0 ( - "[", paste0 (snum, collapse = ", "), - "] on line#", block_line, - " of file [", - fpath_full, - "]" - ) - - return (msg) -} # extract the actual standards numbers from arbitrary text strings, first # capturing everything inside first "[...]": diff --git a/codemeta.json b/codemeta.json index 1f32452..438a586 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/srr", "issueTracker": "https://github.com/ropensci-review-tools/srr/issues", "license": "https://spdx.org/licenses/MIT", - "version": "0.1.3.008", + "version": "0.1.3.009", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R",