Skip to content

Commit

Permalink
address a roxygen doc mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
radbasa committed Jan 26, 2024
1 parent 071cce3 commit f1937de
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 70 deletions.
69 changes: 69 additions & 0 deletions R/box_linters.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
#' Box library function import count linter
#'
#' Checks that function imports do not exceed the defined `max`.
#'
#' @param max Maximum function imports allowed between `[` and `]`. Defaults to 8.
#'
#' @return A custom linter function for use with `r-lib/lintr`.
#'
#' @examples
#' # will produce lints
#' lintr::lint(
#' text = "box::use(package[one, two, three, four, five, six, ])",
#' linters = box_func_import_count_linter()
#' )
#'
#' lintr::lint(
#' text = "box::use(package[one, two, three, four, ])",
#' linters = box_func_import_count_linter(3)
#' )
#'
#' # okay
#' lintr::lint(
#' text = "box::use(package[one, two, three, four, five, ])",
#' linters = box_func_import_count_linter()
#' )
#'
#' lintr::lint(
#' text = "box::use(package[one, two, three, ])",
#' linters = box_func_import_count_linter(3)
#' )
#'
#' @export
box_func_import_count_linter <- function(max = 8L) {
xpath <- glue::glue("//SYMBOL_PACKAGE[
(text() = 'box' and
following-sibling::SYMBOL_FUNCTION_CALL[text() = 'use'])
]
/parent::expr
/parent::expr
/descendant::OP-LEFT-BRACKET[
count(
following-sibling::expr[
count(. | ..//OP-RIGHT-BRACKET/preceding-sibling::expr) =
count(../OP-RIGHT-BRACKET/preceding-sibling::expr)
]
) > {max}
]
/parent::expr")

lint_message <- glue::glue("Limit the function imports to a max of {max}.")

lintr::Linter(function(source_expression) {
if (!lintr::is_lint_level(source_expression, "file")) {
return(list())
}

xml <- source_expression$full_xml_parsed_content

bad_expr <- xml2::xml_find_all(xml, xpath)

lintr::xml_nodes_to_lints(
bad_expr,
source_expression = source_expression,
lint_message = lint_message,
type = "style"
)
})
}

#' Box library universal import linter
#'
#' Checks that all function imports are explicit. `package[...]` is not used.
Expand Down
68 changes: 0 additions & 68 deletions R/linter_box_function_import_count_linter.R

This file was deleted.

4 changes: 2 additions & 2 deletions man/box_func_import_count_linter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f1937de

Please sign in to comment.