Closed
Description
We have an unexported make_linter_from_regex()
helper:
lintr/R/make_linter_from_regex.R
Line 1 in f8bb91e
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.