Skip to content

Commit

Permalink
Merge 105d814 into 2b62a3a
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Aug 2, 2023
2 parents 2b62a3a + 105d814 commit 6fb9fb9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export(with_id)
export(xml_nodes_to_lints)
export(yoda_test_linter)
importFrom(cyclocomp,cyclocomp)
importFrom(glue,glue)
importFrom(rex,character_class)
importFrom(rex,re_matches)
importFrom(rex,re_substitutes)
Expand Down
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()` finds function usages inside `glue()` calls to avoid false positives for "unused objects" (#2029, @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
1 change: 1 addition & 0 deletions R/lintr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"_PACKAGE"

## lintr namespace: start
#' @importFrom glue glue
#' @importFrom rex rex regex re_matches re_substitutes character_class
#' @importFrom stats na.omit
#' @importFrom utils capture.output head getParseData relist
Expand Down
1 change: 0 additions & 1 deletion R/object_usage_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ extract_glued_symbols <- function(expr) {
expr,
xpath = paste0(
"descendant::SYMBOL_FUNCTION_CALL[text() = 'glue']/", # a glue() call
"preceding-sibling::NS_GET/preceding-sibling::SYMBOL_PACKAGE[text() = 'glue']/", # qualified with glue::
"parent::expr[",
# without .envir or .transform arguments
"not(following-sibling::SYMBOL_SUB[text() = '.envir' or text() = '.transform']) and",
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-object_usage_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,15 @@ test_that("interprets glue expressions", {
}
"), NULL, linter)

# no need for namespace-qualification
expect_lint(trim_some("
glue <- glue::glue # imitate this being an @import
fun <- function() {
local_var <- 42
glue('The answer is {local_var}.')
}
"), NULL, linter)

# multiple variables in different interpolations
expect_lint(trim_some("
fun <- function() {
Expand Down

0 comments on commit 6fb9fb9

Please sign in to comment.