Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring with XML node helpers #2207

Merged
merged 6 commits into from
Sep 22, 2023
Merged

Minor refactoring with XML node helpers #2207

merged 6 commits into from
Sep 22, 2023

Conversation

IndrajeetPatil
Copy link
Collaborator

@IndrajeetPatil IndrajeetPatil commented Sep 21, 2023

Well, not truly a refactoring because I am changing one error message.

@codecov-commenter
Copy link

codecov-commenter commented Sep 21, 2023

Codecov Report

Merging #2207 (c2bb2a0) into main (d44de7f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head c2bb2a0 differs from pull request most recent head 4d4dbea. Consider uploading reports for the commit 4d4dbea to get more accurate results

@@           Coverage Diff           @@
##             main    #2207   +/-   ##
=======================================
  Coverage   99.65%   99.65%           
=======================================
  Files         113      113           
  Lines        5161     5167    +6     
=======================================
+ Hits         5143     5149    +6     
  Misses         18       18           
Files Changed Coverage Δ
R/utils.R 99.12% <100.00%> (ø)
R/xml_nodes_to_lints.R 100.00% <100.00%> (ø)
R/xp_utils.R 100.00% <100.00%> (ø)

Comment on lines +99 to +103
is_node <- function(xml) inherits(xml, "xml_node")
is_nodeset <- function(xml) inherits(xml, "xml_nodeset")
is_nodeset_like <- function(xml) {
inherits(xml, "xml_nodeset") ||
(is.list(xml) && all(vapply(xml, inherits, logical(1L), what = "xml_node")))
is_nodeset(xml) ||
(is.list(xml) && all(vapply(xml, is_node, logical(1L))))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These helpers can probably move to the XML utils file (#2201).

R/xp_utils.R Outdated
is_valid_expr <- is_node(expr) || is_nodeset(expr)
if (!is_valid_expr) {
stop(
"Expected an xml_nodeset, a list of xml_nodes or an xml_node, got an object of class(es): ",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is inconsistent with the test (re list of nodes)

Copy link
Collaborator

@AshesITR AshesITR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it's worth it to factor out inherits(x, "xml_node") into its own helper given it has so few call sites.
The error message improvement seems good, though.

Maybe revert to inherits() and keep the improved error message?

@IndrajeetPatil
Copy link
Collaborator Author

Not sure it's worth it to factor out inherits(x, "xml_node") into its own helper given it has so few call sites. The error message improvement seems good, though.

But it has five different call sites, and everywhere the same inherits() call is repeated. I think this deserves a separate function.

@AshesITR AshesITR merged commit 710d6bb into main Sep 22, 2023
20 checks passed
@AshesITR AshesITR deleted the is-node-helpers branch September 22, 2023 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants