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

Handle unused variable with glue #352

Closed
denrou opened this issue Oct 24, 2018 · 5 comments
Closed

Handle unused variable with glue #352

denrou opened this issue Oct 24, 2018 · 5 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@denrou
Copy link

denrou commented Oct 24, 2018

The following code gives a warning when lint is applied:

library(glue)
test <- function() {
  x <- 1
  glue("{x}")
}

The warning is local variable 'x' assigned but may not be used.

It appears the linter object_usage_linter refers to codetools::checkUsage, which is not available on github unfortunately (so I can't open an issue). I was wondering if this issue could be handle by lintr directly or if a workaround exists.

For now, I applied a #nolint (unused variable) for each problematic line.

@russHyde russHyde added the bug an unexpected problem or unintended behavior label Jan 12, 2019
@russHyde
Copy link
Collaborator

russHyde commented Aug 28, 2019

Reprex:

expect_lint(
  "library(glue)\ntest <- function() {\n  x <- 1\nglue::glue('{x}')\n}\n",
  NULL,
  object_usage_linter)

@russHyde
Copy link
Collaborator

Similar to the object_usage_linter issue in #358

@jimhester
Copy link
Member

The object usage linter now respects variables declared in utils::globalVariables(), so you can add them there to avoid these warnings.

@dragosmg
Copy link
Collaborator

dragosmg commented Feb 17, 2020

I'm not quite sure why, but declaring global variables with utils doesn't seem to work for me. object_usage_linter() still complains when i define a variable and the use it only with glue::glue.

I think the way the check has been implemented in object_usage_linter() reads the global variables (declared_globals) after the package has been installed, while I usually run lintr::lint_package() before installing the new version. Is this the desired behaviour or am I missing anything?

Maybe useful to mention I am using the latest dev version of lintr (2.0.0.9000).

@dragosmg dragosmg reopened this Feb 17, 2020
@jimhester
Copy link
Member

You need to install the package before linting it.

jonkeane pushed a commit to apache/arrow that referenced this issue Aug 2, 2022
The package should be installed before running `lintr::ling_package()` or `lintr::expect_lint_free()` (our case), otherwise we could encounter some false positives.

See r-lib/lintr#352 (comment) and r-lib/lintr#406 (comment)


Authored-by: Dragoș Moldovan-Grünfeld <dragos.mold@gmail.com>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants