Skip to content

Commit

Permalink
switch away from //expr XPaths (#1586)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Oct 2, 2022
1 parent c9bf39e commit 595e1a1
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions R/paste_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@
#' @seealso [linters] for a complete list of linters available in lintr.
#' @export
paste_linter <- function(allow_empty_sep = FALSE, allow_to_string = FALSE) {
sep_xpath <- "//expr[
expr[1][SYMBOL_FUNCTION_CALL[text() = 'paste']]
and SYMBOL_SUB[text() = 'sep']/following-sibling::expr[1][STR_CONST]
]"
sep_xpath <- "
//SYMBOL_FUNCTION_CALL[text() = 'paste']
/parent::expr
/following-sibling::SYMBOL_SUB[text() = 'sep' and following-sibling::expr[1][STR_CONST]]
/parent::expr
"

to_string_xpath <- glue::glue("//expr[
expr[1][SYMBOL_FUNCTION_CALL[text() = 'paste' or text() = 'paste0']]
and count(expr) = 3
to_string_xpath <- "
//SYMBOL_FUNCTION_CALL[text() = 'paste' or text() = 'paste0']
/parent::expr
/parent::expr[
count(expr) = 3
and SYMBOL_SUB[text() = 'collapse']/following-sibling::expr[1][STR_CONST]
]")

paste0_sep_xpath <- "//expr[
expr[1][SYMBOL_FUNCTION_CALL[text() = 'paste0']]
and SYMBOL_SUB[text() = 'sep']
]"

paste0_sep_xpath <- "
//SYMBOL_FUNCTION_CALL[text() = 'paste0']
/parent::expr
/following-sibling::SYMBOL_SUB[text() = 'sep']
/parent::expr
"

Linter(function(source_expression) {
if (!is_lint_level(source_expression, "expression")) {
return(list())
Expand Down

0 comments on commit 595e1a1

Please sign in to comment.