Adds a user-supplied diagnostic to every subsequent checktor() run without
editing checktor's source. The check runs alongside the built-ins in its
category, appears in issues(), tidy() and the printed report, and counts
toward the verdict at the severity tier you declare.
Usage
register_check(
name,
fn,
category = CHECK_CATEGORIES,
severity = c("robustness", "policy", "opinion")
)Arguments
- name
Character. The check's key, used in results and reports. Must not clash with a built-in check name.
- fn
A function returning a
checktor_check_result(), the same shape as anydiagnose_*function. It is called asfn(path, verbose). If it also declares aparsedargument (forcodeandpolicychecks) or adescargument (fordescriptionchecks), checktor forwards its shared parse cache so the check does not re-read the sources.- category
Character. Which category the check joins: one of
"code","description","documentation","general","policy".- severity
Character. The tier the check reports at: one of
"robustness"(default),"policy", or"opinion". This decides whether a finding counts against a clean bill of health underchecktor()'sseverityargument.
Examples
# A house rule: flag any call to a banned helper.
diagnose_no_banned <- function(path, verbose = TRUE, parsed = NULL) {
if (is.null(parsed)) parsed <- read_r_xml(path)
issues <- undesirable_function_check(parsed, "banned_helper")
checktor_check_result(length(issues) == 0L, issues, "no banned_helper()")
}
register_check("no_banned", diagnose_no_banned,
category = "code", severity = "policy")
registered_checks()
#> check category severity
#> 1 no_banned code policy
unregister_check("no_banned")