Convenience function for converting nodes matched by XPath-based
linter logic into a Lint()
object to return.
Usage
xml_nodes_to_lints(
xml,
source_expression,
lint_message,
type = c("style", "warning", "error"),
column_number_xpath = range_start_xpath,
range_start_xpath = "number(./@col1)",
range_end_xpath = "number(./@col2)"
)
Arguments
- xml
An
xml_node
object (to generate oneLint
) or anxml_nodeset
object (to generate severalLint
s), e.g. as returned byxml2::xml_find_all()
orxml2::xml_find_first()
or a list ofxml_node
objects.- source_expression
A source expression object, e.g. as returned typically by
lint()
, or more generally byget_source_expressions()
.- lint_message
The message to be included as the
message
to theLint
object. Iflint_message
is a character vector the same length asxml
, thei
-th lint will be given thei
-th message.- type
type of lint.
- column_number_xpath
XPath expression to return the column number location of the lint. Defaults to the start of the range matched by
range_start_xpath
. See details for more information.- range_start_xpath
XPath expression to return the range start location of the lint. Defaults to the start of the expression matched by
xml
. See details for more information.- range_end_xpath
XPath expression to return the range end location of the lint. Defaults to the end of the expression matched by
xml
. See details for more information.
Details
The location XPaths, column_number_xpath
, range_start_xpath
and range_end_xpath
are evaluated using
xml2::xml_find_num()
and will usually be of the form "number(./relative/xpath)"
.
Note that the location line number cannot be changed and lints spanning multiple lines will ignore range_end_xpath
.
column_number_xpath
and range_start_xpath
are assumed to always refer to locations on the starting line of the
xml
node.