Skip to content

Commit

Permalink
customize lengths_linter for data.table usage (#6100)
Browse files Browse the repository at this point in the history
customize lengths_linter for data.table usage

comment
  • Loading branch information
MichaelChirico authored May 4, 2024
1 parent 05c1d6c commit 4e48c47
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .ci/linters/dt_lengths_linter.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This is lintr::lengths_linter(), but including 'vapply_1i()' which is more common internally in data.table
# alternatively, this could be defined with something like
# dt_lengths_linter <- lintr::lengths_linter()
# local({ # to remove 'e'
# e <- environment(dt_lengths_linter)
# e$function_names <- c(evalq(function_names, e), "vapply_1i")
# })
# but that feels more fragile than this.
dt_lengths_linter <- lintr::make_linter_from_function_xpath(
function_names = c("sapply", "vapply", "vapply_1i", "map_int", "map_dbl"),
xpath = "parent::expr/parent::expr[expr/SYMBOL[text() = 'length']]",
lint_message = "Use lengths() to find the length of each element in a list."
)

0 comments on commit 4e48c47

Please sign in to comment.