Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assume glue is glue::glue #2032

Merged
merged 5 commits into from
Aug 2, 2023
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 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