Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions R/any_duplicated_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ any_duplicated_linter <- function() {
Linter(linter_level = "expression", function(source_expression) {
# NB: need two parents given three parent::expr in XPath and stripped comments.
xml <- source_expression$xml_parsed_content |>
xml_find_all("//EQ | //NE | //GT | //LT") |>
xml_parent() |>
xml_parent() |>
xml_find_all("(//EQ | //NE | //GT | //LT)/parent::*/parent::*") |>
strip_comments_from_subtree()

xml_calls <- source_expression$xml_find_function_calls("any")
Expand Down
7 changes: 4 additions & 3 deletions R/coalesce_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ coalesce_linter <- function() {
")

Linter(linter_level = "expression", function(source_expression) {
null_calls <- xml_parent(xml_parent(xml_parent(
source_expression$xml_find_function_calls("is.null")
)))
null_calls <- xml_find_all(
source_expression$xml_find_function_calls("is.null"),
"parent::*/parent::*/parent::*"
)
null_calls <- strip_comments_from_subtree(null_calls)
bad_expr <- xml_find_all(null_calls, xpath)
is_negation <- !is.na(xml_find_first(bad_expr, "expr/OP-EXCLAMATION"))
Expand Down
3 changes: 1 addition & 2 deletions R/is_numeric_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ is_numeric_linter <- function() {
xml <- source_expression$xml_parsed_content

or_expr <- xml |>
xml_find_all("//OR2") |>
xml_parent() |>
xml_find_all("//OR2/parent::*") |>
strip_comments_from_subtree() |>
xml_find_all(or_xpath)
or_lints <- xml_nodes_to_lints(
Expand Down
14 changes: 8 additions & 6 deletions R/regex_subset_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ regex_subset_linter <- function() {
stringr_xpath <- glue(xpath_fmt, arg_pos = 2L)

Linter(linter_level = "expression", function(source_expression) {
grep_calls <- xml_parent(xml_parent(xml_parent(
source_expression$xml_find_function_calls(c("grepl", "grep"))
)))
grep_calls <- xml_find_all(
source_expression$xml_find_function_calls(c("grepl", "grep")),
"parent::*/parent::*/parent::*"
)
grep_calls <- strip_comments_from_subtree(grep_calls)
grep_expr <- xml_find_all(grep_calls, grep_xpath)

Expand All @@ -76,9 +77,10 @@ regex_subset_linter <- function() {
type = "warning"
)

stringr_calls <- xml_parent(xml_parent(xml_parent(
source_expression$xml_find_function_calls(c("str_detect", "str_which"))
)))
stringr_calls <- xml_find_all(
source_expression$xml_find_function_calls(c("str_detect", "str_which")),
"parent::*/parent::*/parent::*"
)
stringr_calls <- strip_comments_from_subtree(stringr_calls)
stringr_expr <- xml_find_all(stringr_calls, stringr_xpath)

Expand Down
11 changes: 6 additions & 5 deletions R/sort_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ sort_linter <- function() {
arg_values_xpath <- glue("{arguments_xpath}/following-sibling::expr[1]")

Linter(linter_level = "expression", function(source_expression) {
order_calls <- strip_comments_from_subtree(xml_parent(xml_parent(
source_expression$xml_find_function_calls("order")
)))
order_calls <- source_expression$xml_find_function_calls("order") |>
xml_find_all("parent::*/parent::*") |>
strip_comments_from_subtree()

order_expr <- xml_find_all(order_calls, order_xpath)

Expand Down Expand Up @@ -137,8 +137,9 @@ sort_linter <- function() {
type = "warning"
)

sort_calls <- xml_parent(xml_parent(xml_parent(source_expression$xml_find_function_calls("sort"))))
sort_calls <- strip_comments_from_subtree(sort_calls)
sort_calls <- source_expression$xml_find_function_calls("sort") |>
xml_find_all("parent::*/parent::*/parent::*") |>
strip_comments_from_subtree()
sorted_expr <- xml_find_all(sort_calls, sorted_xpath)

sorted_op <- xml_text(xml_find_first(sorted_expr, "*[2]"))
Expand Down
2 changes: 1 addition & 1 deletion R/source_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @noRd
build_xml_find_function_calls <- function(xml) {
function_call_cache <- xml_find_all(xml, "//SYMBOL_FUNCTION_CALL/parent::expr")
function_call_cache <- xml_parent(xml_find_all(xml, "//SYMBOL_FUNCTION_CALL"))
names(function_call_cache) <- get_r_string(function_call_cache, "SYMBOL_FUNCTION_CALL")

s4_slot_cache <- xml_find_all(xml, "//SLOT/parent::expr[following-sibling::OP-LEFT-PAREN]")
Expand Down
7 changes: 4 additions & 3 deletions R/string_boundary_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ string_boundary_linter <- function(allow_grepl = FALSE) {
))
}

substr_calls <- xml_parent(xml_parent(
source_expression$xml_find_function_calls(c("substr", "substring"))
))
substr_calls <- xml_find_all(
source_expression$xml_find_function_calls(c("substr", "substring")),
"parent::*/parent::*"
)
is_str_comparison <- !is.na(xml_find_first(substr_calls, string_comparison_xpath))
substr_calls <- strip_comments_from_subtree(substr_calls[is_str_comparison])
substr_expr <- xml_find_all(substr_calls, substr_xpath)
Expand Down
Loading