From e83849c5df5f4ac22225682a8ee11f5dcc39f5fb Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Tue, 23 Apr 2024 14:50:14 -0700 Subject: [PATCH 1/3] customize lengths_linter for data.table usage --- .ci/linters/dt_lengths_linter.R | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .ci/linters/dt_lengths_linter.R diff --git a/.ci/linters/dt_lengths_linter.R b/.ci/linters/dt_lengths_linter.R new file mode 100644 index 000000000..bca3f25ef --- /dev/null +++ b/.ci/linters/dt_lengths_linter.R @@ -0,0 +1,5 @@ +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." +) From c24c1d47ed114d8334fd0b45447b539590406c72 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Tue, 23 Apr 2024 14:50:46 -0700 Subject: [PATCH 2/3] comment --- .ci/linters/dt_lengths_linter.R | 1 + 1 file changed, 1 insertion(+) diff --git a/.ci/linters/dt_lengths_linter.R b/.ci/linters/dt_lengths_linter.R index bca3f25ef..6b09063da 100644 --- a/.ci/linters/dt_lengths_linter.R +++ b/.ci/linters/dt_lengths_linter.R @@ -1,3 +1,4 @@ +# This is lintr::lengths_linter(), but including 'vapply_1i()' which is more common internally in data.table 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']]", From dc2d6edfc1ab0ed33c65e8c250e0b084ee77fb36 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 2 May 2024 22:15:36 -0700 Subject: [PATCH 3/3] note an alternative implementation we eschew --- .ci/linters/dt_lengths_linter.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.ci/linters/dt_lengths_linter.R b/.ci/linters/dt_lengths_linter.R index 6b09063da..3ca218c4e 100644 --- a/.ci/linters/dt_lengths_linter.R +++ b/.ci/linters/dt_lengths_linter.R @@ -1,4 +1,11 @@ # 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']]",