Skip to content

Export a make_linter_from_xpath() helper? #2064

Closed
@MichaelChirico

Description

@MichaelChirico

We have an unexported make_linter_from_regex() helper:

make_linter_from_regex <- function(regex,

But that's only good for regex-based logic, which has a lot of pitfalls as we've learned.

Today I found myself trying to do some quick ad-hoc linting of a codebase and it was made more painful by the need to remember all the boilerplate for constructing a linter:

linter <- Linter(function(source_expression) {
   if (!is_lint_level(source_expression, $<LEVEL>)) return(list)
   xml <- source_expression$full_xml_parsed_content
   expr <- xml_find_all(xml, $<XPATH>)
   xml_nodes_to_lints(expr, source_expression, $<MESSAGE>, $<TYPE>)
 })

We could offer a helper to quickly generate a compliant linter function given an XPath. Proposed workflow:

new_linter <- make_linter_from_xpath($<XPATH>) # reasonable defaults for everything, including $<MESSAGE>
lint_dir(linters = new_linter)

In fact we could probably use that helper to generate many of our own linters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions