Skip to content

Commit 6fb9fb9

Browse files
Merge 105d814 into 2b62a3a
2 parents 2b62a3a + 105d814 commit 6fb9fb9

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export(with_id)
142142
export(xml_nodes_to_lints)
143143
export(yoda_test_linter)
144144
importFrom(cyclocomp,cyclocomp)
145+
importFrom(glue,glue)
145146
importFrom(rex,character_class)
146147
importFrom(rex,re_matches)
147148
importFrom(rex,re_substitutes)

NEWS.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
## Changes to defaults
88

99
* `assignment_linter()` lints the {magrittr} assignment pipe `%<>%` (#2008, @MichaelChirico). This can be deactivated by setting the new argument `allow_pipe_assign` to `TRUE`.
10-
* `object_usage_linter()` finds function usages inside `glue()` calls to avoid false positives for "unused objects" (#2029, @MichaelChirico).
10+
* `object_usage_linter()`:
11+
+ assumes `glue()` is `glue::glue()` when `interpret_glue=TRUE` (#2032, @MichaelChirico).
12+
+ finds function usages inside `glue()` calls to avoid false positives for "unused objects" (#2029, @MichaelChirico).
1113

1214
# lintr 3.1.0
1315

R/lintr-package.R

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"_PACKAGE"
99

1010
## lintr namespace: start
11+
#' @importFrom glue glue
1112
#' @importFrom rex rex regex re_matches re_substitutes character_class
1213
#' @importFrom stats na.omit
1314
#' @importFrom utils capture.output head getParseData relist

R/object_usage_linter.R

-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ extract_glued_symbols <- function(expr) {
170170
expr,
171171
xpath = paste0(
172172
"descendant::SYMBOL_FUNCTION_CALL[text() = 'glue']/", # a glue() call
173-
"preceding-sibling::NS_GET/preceding-sibling::SYMBOL_PACKAGE[text() = 'glue']/", # qualified with glue::
174173
"parent::expr[",
175174
# without .envir or .transform arguments
176175
"not(following-sibling::SYMBOL_SUB[text() = '.envir' or text() = '.transform']) and",

tests/testthat/test-object_usage_linter.R

+9
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,15 @@ test_that("interprets glue expressions", {
352352
}
353353
"), NULL, linter)
354354

355+
# no need for namespace-qualification
356+
expect_lint(trim_some("
357+
glue <- glue::glue # imitate this being an @import
358+
fun <- function() {
359+
local_var <- 42
360+
glue('The answer is {local_var}.')
361+
}
362+
"), NULL, linter)
363+
355364
# multiple variables in different interpolations
356365
expect_lint(trim_some("
357366
fun <- function() {

0 commit comments

Comments
 (0)