Skip to content

Commit

Permalink
Merge branch 'main' into assume-glue
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Aug 2, 2023
2 parents 4d5f12e + c0ac772 commit 11fac3f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
## 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()` assumes `glue()` is `glue::glue()` when `interpret_glue=TRUE` (#2032, @MichaelChirico).
* `object_usage_linter()`:
+ assumes `glue()` is `glue::glue()` when `interpret_glue=TRUE` (#2032, @MichaelChirico).
+ 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 @@ -222,7 +222,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 @@ -418,6 +418,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

0 comments on commit 11fac3f

Please sign in to comment.