Skip to content

Commit

Permalink
Allow functions called as object names (#128)
Browse files Browse the repository at this point in the history
* see functions called as objects without ()
  • Loading branch information
radbasa authored Aug 5, 2024
1 parent 6254499 commit 17c7979
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: box.linters
Title: Linters for 'box' Modules
Version: 0.10.0.9002
Version: 0.10.0.9003
Authors@R:
c(
person("Ricardo Rodrigo", "Basa", role = c("aut", "cre"), email = "[email protected]"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# box.linters (development version)

* `box_unused_att_pkg_fun_linter()` allows functions passed into other functions by name without `().
* `package::function()` check is exclusive to `namespace_function_calls()`.
* Move `treesitter` dependencies to Suggests because of the R >= 4.3.0 requirement. Functions that depend on `treesitter` now check if it is installed and handle the absence gracefully.

Expand Down
3 changes: 2 additions & 1 deletion R/box_unused_attached_pkg_fun_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ box_unused_att_pkg_fun_linter <- function() {
FUN.VALUE = character(1)
)

object_calls <- get_object_calls(xml)
glue_object_calls <- get_objects_in_strings(xml)
all_calls_text <- c(function_calls$text, glue_object_calls)
all_calls_text <- c(function_calls$text, glue_object_calls, object_calls$text)

lapply(attached_functions$xml, function(fun_import) {
fun_import_text <- xml2::xml_text(fun_import)
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-box_unused_attached_pkg_fun_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,18 @@ test_that("box_unused_att_pkg_fun_linter blocks unused functions in glue string

lintr::expect_lint(bad_box_usage, list(message = lint_message_1), linters = linter)
})

test_that("box_unused_att_pkg_fun_linter allows functions called as objects", {
linter <- box_unused_att_pkg_fun_linter()

good_box_usage <- "box::use(
dplyr[storms],
purrr[map_chr],
stringr[str_to_upper],
)
my_names <- map_chr(names(storms), str_to_upper)
"

lintr::expect_lint(good_box_usage, NULL, linters = linter)
})

0 comments on commit 17c7979

Please sign in to comment.