From 0f6d69e2952cf67bda1e729b1baf62c8b9e44664 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 2 Aug 2023 16:45:24 +0000 Subject: [PATCH] assume glue is glue::glue --- NEWS.md | 1 + R/object_usage_linter.R | 1 - tests/testthat/test-object_usage_linter.R | 8 ++++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 4cddc89bd..1885a6ba8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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()` assumes `glue()` is `glue::glue()` when `interpret_glue=TRUE` (#2032, @MichaelChirico). # lintr 3.1.0 diff --git a/R/object_usage_linter.R b/R/object_usage_linter.R index 856b5e77a..ce79b5141 100644 --- a/R/object_usage_linter.R +++ b/R/object_usage_linter.R @@ -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", diff --git a/tests/testthat/test-object_usage_linter.R b/tests/testthat/test-object_usage_linter.R index bb29ecf96..f5ec5ade7 100644 --- a/tests/testthat/test-object_usage_linter.R +++ b/tests/testthat/test-object_usage_linter.R @@ -352,6 +352,14 @@ test_that("interprets glue expressions", { } "), NULL, linter) + # no need for namespace-qualification + expect_lint(trim_some(" + fun <- function() { + local_var <- 42 + glue('The answer is {local_var}.') + } + "), NULL, linter) + # multiple variables in different interpolations expect_lint(trim_some(" fun <- function() {