rhino icon indicating copy to clipboard operation
rhino copied to clipboard

Box usage linter

Open radbasa opened this issue 1 year ago • 2 comments

Lint box package imports:

Package imports

  • [x] Should lint if a package$function() does not exist
  • [ ] Should lint if an imported package is not used
  • [x] Should lint if an imported function is not used
  • [x] Should lint if an imported function does not exist in the package
  • [x] Should lint if function called was not imported in package[function]
  • [x] Should not lint if a function called is from a base package (for example, sum())
  • [x] Should not lint if all functions of an imported package are not used

Local functions

  • [x] Should lint if a declared function is unused - may have to remove this. our box modules are libraries of functions
  • [ ] Should lint if an R6 class private$ object (method or property) is not used internally.
  • [ ] Should lint if an R6 class self$ object internal method call is invalid
  • [ ] Should not lint if an object is the same as declared in the enclosing function signature
  • [ ] Should lint if ... is used but not in the function signature

Module imports

radbasa avatar Jan 17 '24 03:01 radbasa

It’s not lintr that has problems with box. It’s codetools::checkUsage(). It’s seeing box_module$function() as a global variable/object, box_module, which was never declared earlier. Object usage linter detects global variables but only if it sees a package. We can use that, but this means we’ll have to copy over several functions from lintr. I needed to do some package:::function() calls to run object usage linter in interactive mode.

radbasa avatar Jan 31 '24 09:01 radbasa

@jakubnowicki How do you feel about this hacky solution:

box_usage_linter <- function(...) {
  mocked_object_usage_linter <- lintr::object_usage_linter(...)
  
  # because lintr::object_usage_linter() has
  # declared_globals <- lintr:::try_silently(globalVariables(package = pkg_name %||% globalenv()))
  # let's mock `globalVariables()` to return the names of the attached box modules and functions
  mockery::stub(mocked_object_usage_linter, "globalVariables", function(...) { c("box_module") })
  mocked_object_usage_linter
}

test_file <- file.path("test_scripts", "objects.R")

lintr::lint(test_file, linters = box_usage_linter())

radbasa avatar Feb 07 '24 08:02 radbasa

Closing this issue.

Go to box.linters instead.

radbasa avatar Aug 05 '24 05:08 radbasa