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

[LINT_BUG]: Objects exported from packages and functions run in purrr::map causes lint errors #124

Open
vibalre opened this issue Jul 24, 2024 · 2 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@vibalre
Copy link
Member

vibalre commented Jul 24, 2024

box.linters version

0.10.0

Sample source code to lint

# module.R
#' @export
my_constant <- 42

#' @export
my_function <- function(x) {
  x >= 1
}

# object.R
box::use(
  dplyr[storms],
  purrr[map, map_chr],
  stringr[str_to_upper],
)

box::use(
  . / module[my_constant, my_function],
)

#' @export
my_names <-
  map_chr(
    names(storms),
    str_to_upper
  )

#' @export
my_new_constant <- my_constant / 3

#' @export
my_answer <- map(c(1, 2, 3), my_function)

Lint command used

lintr::lint(
    "object.R",
    linters = lintr::linters_with_defaults(defaults = box.linters::rhino_default_linters)
)

Lint result

Line 2[box_pkg_fun_exists_linter] Function not exported by package.
Line 2[box_unused_attached_pkg_fun_linter] Imported function unused.
Line 4[box_unused_attached_pkg_fun_linter] Imported function unused.

Expected result

There should be no lint errors.

@radbasa
Copy link
Collaborator

radbasa commented Jul 24, 2024

@jakubnowicki I think I know what's going on here. Or rather, what's not going on.

A data object from a package is being imported. We currently use getNamespaceExports() to determine what functions a package exports. This does not return data objects.

And because the unused attached package function linter assumes all the attached objects from a package are function, it is complaining that storm() is not used.

The unused str_to_upper is the same. The linter is looking for a function token with the name str_to_upper. The str_to_upper in the map_chr() call is a plain object token.

Issue 1 will need to wait for the full support for box namespace exports from {box}.

Issue 2 and 3 can be handled within the linter functions.

@radbasa radbasa self-assigned this Jul 24, 2024
@radbasa radbasa added bug Something isn't working good first issue Good for newcomers labels Jul 24, 2024
@radbasa
Copy link
Collaborator

radbasa commented Aug 5, 2024

Issues 2 and 3 handled by PR 128.

Leaving this issue open for issue 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants