Skip to content

Commit

Permalink
Merge branch 'main' into feature/return_linter
Browse files Browse the repository at this point in the history
  • Loading branch information
AshesITR authored Nov 23, 2023
2 parents f89c8bc + 97182b7 commit 325205c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions R/package_hooks_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ package_hooks_linter <- function() {
# lints here will hit the function <expr>,
# this path returns to the corresponding namespace hook's name
ns_calls <- xp_text_in_table(c(".onLoad", ".onAttach", ".onDetach", ".Last.lib"))

# usually any given package will have one or maybe two files defining namespace hooks.
# given the number of checks, then, it's prudent to check first if any such hook is defined,
# exiting early if not.
any_hook_xpath <- glue("(//FUNCTION | //OP-LAMBDA)/parent::expr/preceding-sibling::expr/SYMBOL[{ns_calls}]")

hook_xpath <- sprintf("string(./ancestor::expr/expr/SYMBOL[%s])", ns_calls)

load_arg_name_xpath <- "
Expand Down Expand Up @@ -121,11 +127,16 @@ package_hooks_linter <- function() {
"

Linter(function(source_expression) {
if (!is_lint_level(source_expression, "expression")) {
if (!is_lint_level(source_expression, "file")) {
return(list())
}

xml <- source_expression$xml_parsed_content
xml <- source_expression$full_xml_parsed_content

any_hook <- xml_find_first(xml, any_hook_xpath)
if (is.na(any_hook)) {
return(list())
}

# inherits: source_expression, bad_call_xpaths
bad_msg_call_lints <- function(xml, hook) {
Expand Down

0 comments on commit 325205c

Please sign in to comment.