Skip to content

Commit

Permalink
Remove code to deal with broken namespaces (#1653)
Browse files Browse the repository at this point in the history
* Remove code to deal with broken namespaces

Closes #1650

* retain comment

* address comments

* Update namespace_linter.R

* Update namespace_linter.R

* Update namespace_linter.R

Co-authored-by: Michael Chirico <chiricom@google.com>
  • Loading branch information
IndrajeetPatil and MichaelChirico authored Oct 9, 2022
1 parent 80c38c5 commit 09adcf3
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions R/namespace_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,15 @@ namespace_linter <- function(check_exports = TRUE, check_nonexports = TRUE) {
return(lints)
}

## Case 2 (rare?): pkg namespace is broken in pkg::foo
## Case 2/3/4: problems with foo in pkg::foo / pkg:::foo

# run here, not in the factory, to allow for run- vs. "compile"-time differences in package structure
namespaces <- lapply(packages, function(package) tryCatch(getNamespace(package), error = identity))
failed_namespace <- vapply(namespaces, inherits, "condition", FUN.VALUE = logical(1L))

if (any(failed_namespace)) {
lints <- c(lints, xml_nodes_to_lints(
package_nodes[failed_namespace],
source_expression = source_expression,
lint_message = vapply(namespaces[failed_namespace], conditionMessage, character(1L)),
type = "warning"
))

ns_nodes <- ns_nodes[!failed_namespace]
packages <- packages[!failed_namespace]
namespaces <- namespaces[!failed_namespace]
stop("Failed to retrieve namespaces for one or more of the packages. Please report this issue.", call. = FALSE)
}

## Case 3/4/5: problems with foo in pkg::foo / pkg:::foo

ns_get <- xml2::xml_text(ns_nodes) == "::"
symbol_nodes <- xml2::xml_find_all(ns_nodes, "following-sibling::*[1]")
symbols <- get_r_string(symbol_nodes)
Expand Down Expand Up @@ -107,7 +95,7 @@ get_all_exports <- function(namespace) {
build_ns_get_int_lints <- function(packages, symbols, symbol_nodes, namespaces, source_expression) {
lints <- list()

## Case 3: foo does not exist in pkg:::foo
## Case 2: foo does not exist in pkg:::foo

non_symbols <- !vapply(
seq_along(symbols),
Expand All @@ -127,7 +115,7 @@ build_ns_get_int_lints <- function(packages, symbols, symbol_nodes, namespaces,
symbol_nodes <- symbol_nodes[!non_symbols]
}

## Case 4: foo is already exported pkg:::foo
## Case 3: foo is already exported pkg:::foo

exported <- vapply(
seq_along(symbols),
Expand All @@ -150,7 +138,7 @@ build_ns_get_int_lints <- function(packages, symbols, symbol_nodes, namespaces,
build_ns_get_lints <- function(packages, symbols, symbol_nodes, namespaces, source_expression) {
lints <- list()

## Case 5: foo is not an export in pkg::foo
## Case 4: foo is not an export in pkg::foo

unexported <- !vapply(
seq_along(symbols),
Expand All @@ -165,5 +153,6 @@ build_ns_get_lints <- function(packages, symbols, symbol_nodes, namespaces, sour
type = "warning"
))
}

lints
}

0 comments on commit 09adcf3

Please sign in to comment.