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

namespace_linter() false positives with re-exported functions #1752

Closed
IndrajeetPatil opened this issue Oct 23, 2022 · 4 comments · Fixed by #1753
Closed

namespace_linter() false positives with re-exported functions #1752

IndrajeetPatil opened this issue Oct 23, 2022 · 4 comments · Fixed by #1753
Labels
false-positive code that shouldn't lint, but does

Comments

@IndrajeetPatil
Copy link
Collaborator

library(lintr)

dir <- tempfile()
pkg <- usethis::create_package(dir, open = FALSE, rstudio = FALSE)
setwd(pkg)
fs::dir_create("R")
writeLines(
  c("#' @export", "#' @importFrom magrittr \"%>%\"", "magrittr::`%>%`"), 
  "R/script.R"
)
devtools::document()
#> ℹ Updating file6b4e37419a97 documentation
#> ℹ Loading file6b4e37419a97
#> Writing 'NAMESPACE'
#> Writing 'NAMESPACE'
#> Writing 'reexports.Rd'
readLines("NAMESPACE")
#> [1] "# Generated by roxygen2: do not edit by hand"
#> [2] ""                                            
#> [3] "export(\"%>%\")"                             
#> [4] "importFrom(magrittr,\"%>%\")"

devtools::install(quiet = TRUE)
lintr::lint_package(linters = namespace_linter())
#> R/script.R:3:11: warning: [namespace_linter] '`%>%`' is not exported from {magrittr}.
#> magrittr::`%>%`
#>           ^~~~~

Created on 2022-10-23 with reprex v2.0.2

@IndrajeetPatil IndrajeetPatil added the false-positive code that shouldn't lint, but does label Oct 23, 2022
@AshesITR
Copy link
Collaborator

Seems more related to `%>%` vs. %>%.

@IndrajeetPatil
Copy link
Collaborator Author

@AshesITR
Copy link
Collaborator

AshesITR commented Oct 24, 2022

Sorry for not being clear. I was referring to the bug.
namespace_linter() should treat magrittr::`%>%` (and magrittr::"%>%") as accessing %>% in magrittr, which is exported.

@IndrajeetPatil
Copy link
Collaborator Author

Looks like magrittr::"%>%" already works fine; it's just the ` that seems to throw off this linter. So the solution might be as simple as cleaning up backticks before passing the symbols for namespace checks:

library(lintr)

lint(
  text = "magrittr::`%>%`",
  linters = namespace_linter()
)
#> <text>:1:11: warning: [namespace_linter] '`%>%`' is not exported from {magrittr}.
#> magrittr::`%>%`
#>           ^~~~~

lint(
  text = "magrittr::'%>%'",
  linters = namespace_linter()
)

Created on 2022-10-24 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive code that shouldn't lint, but does
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants