Skip to content

Commit

Permalink
reduce tag-specific 'process' fns to one generic fn for #41
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Aug 27, 2024
1 parent 69e69b9 commit b4297ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 72 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand Down
82 changes: 12 additions & 70 deletions R/roclet.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
)
)
}

Expand Down Expand Up @@ -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))
Expand All @@ -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 "[...]":
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b4297ef

Please sign in to comment.