Skip to content

Export a make_linter_from_xpath() helper? #2064

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

Closed
MichaelChirico opened this issue Aug 9, 2023 · 0 comments · Fixed by #2126
Closed

Export a make_linter_from_xpath() helper? #2064

MichaelChirico opened this issue Aug 9, 2023 · 0 comments · Fixed by #2126
Labels
feature a feature request or enhancement
Milestone

Comments

@MichaelChirico
Copy link
Collaborator

MichaelChirico commented Aug 9, 2023

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.

@MichaelChirico MichaelChirico added the feature a feature request or enhancement label Aug 9, 2023
@MichaelChirico MichaelChirico added this to the 3.1.1 milestone Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant