-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from Appsilon/objects-in-strings
Handle objects in {glue} string templates
- Loading branch information
Showing
17 changed files
with
666 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: box.linters | ||
Title: Linters for 'box' Modules | ||
Version: 0.9.0.9004 | ||
Version: 0.9.0.9005 | ||
Authors@R: | ||
c( | ||
person("Ricardo Rodrigo", "Basa", role = c("aut", "cre"), email = "[email protected]"), | ||
|
@@ -23,7 +23,9 @@ Imports: | |
glue, | ||
lintr (>= 3.0.0), | ||
rlang, | ||
xml2 | ||
stringr, | ||
xml2, | ||
xmlparsedata | ||
Suggests: | ||
box, | ||
covr, | ||
|
@@ -36,10 +38,8 @@ Suggests: | |
rhino, | ||
shiny, | ||
spelling, | ||
stringr, | ||
testthat (>= 3.0.0), | ||
withr, | ||
xmlparsedata | ||
Config/testthat/edition: 3 | ||
Config/testthat/parallel: true | ||
Language: en-US |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#' Get objects used in `glue` string templates | ||
#' | ||
#' @description | ||
#' In `glue`, all text between `{` and `}` is considered code. Literal braces are defined as | ||
#' `{{` and `}}`. Text between double braces are not interpolated. | ||
#' | ||
#' @param xml An xml node list. | ||
#' @return A character vector of object and function names found inside `glue` string templates. | ||
#' @keywords internal | ||
get_objects_in_strings <- function(xml) { | ||
xpath_str_consts <- " | ||
//expr/STR_CONST | ||
" | ||
|
||
all_strings <- extract_xml_and_text(xml, xpath_str_consts) | ||
text_between_braces <- stringr::str_match_all(all_strings$text, "(\\{(?:\\{??[^\\{]*?\\}))") | ||
|
||
tryCatch({ | ||
unlist( | ||
lapply(text_between_braces, function(each_text) { | ||
if (identical(each_text[, 2], character(0))) { | ||
return(NULL) | ||
} | ||
|
||
parsed_code <- parse(text = each_text[, 2], keep.source = TRUE) | ||
xml_parsed_code <- xml2::read_xml(xmlparsedata::xml_parse_data(parsed_code)) | ||
objects_called <- get_object_calls(xml_parsed_code) | ||
functions_calls <- get_function_calls(xml_parsed_code) | ||
|
||
return( | ||
c( | ||
objects_called$text, | ||
functions_calls$text | ||
) | ||
) | ||
}) | ||
) | ||
}, error = function(e) { | ||
return(NULL) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.