Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## Changes to defaults

* `assignment_linter()` lints the {magrittr} assignment pipe `%<>%` (#2008, @MichaelChirico). This can be deactivated by setting the new argument `allow_pipe_assign` to `TRUE`.
* `object_usage_linter()` finds function usages inside `glue()` calls to avoid false positives for "unused objects" (#2029, @MichaelChirico).

# lintr 3.1.0

Expand Down
2 changes: 1 addition & 1 deletion R/object_usage_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ symbol_extractor <- function(text, envir, data) {
parse_data <- utils::getParseData(parsed_text)

# strip backticked symbols; `x` is the same as x.
symbols <- gsub("^`(.*)`$", "\\1", parse_data$text[parse_data$token == "SYMBOL"])
symbols <- gsub("^`(.*)`$", "\\1", parse_data$text[parse_data$token %in% c("SYMBOL", "SYMBOL_FUNCTION_CALL")])
for (sym in symbols) {
assign(sym, NULL, envir = envir)
}
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-object_usage_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,19 @@ test_that("interprets glue expressions", {
glue::glue('The answer is {local_var}.')
}
"), "local_var", object_usage_linter(interpret_glue = FALSE))

# call in glue is caught
expect_lint(
trim_some("
fun <- function() {
local_call <- identity
local_unused_call <- identity
glue::glue('{local_call(1)}')
}
"),
"local_unused_call",
linter
)
})

test_that("errors/edge cases in glue syntax don't fail lint()", {
Expand Down