
#' @include lists.R

CHECKS$no_import_package_as_a_whole <- make_check(

  description = 'Packages are not imported as a whole',
  tags = c("warning", "NAMESPACE"),
  preps = "namespace",

  gp = 'not import packages as a whole, as this can cause name
        clashes between the imported packages,
        especially over time as packages change.
        Instead, import only the specific functions you need.',

  check = function(state) {
    if(inherits(state$namespace, "try-error")) return(na_result())
    imports <- state$namespace$imports
    check_result(all(vapply(imports, length, 1L) > 1))
  }
)

CHECKS$no_export_pattern <- make_check(

  description = "exportPattern in NAMESPACE file",
  tags = c("warning", "NAMESPACE"),
  preps = "namespace",

  gp = 'not use {.code exportPattern} in {.file NAMESPACE}. It can lead to
        exporting functions unintendedly. Instead, export
        functions that constitute the external API of your
        package.',

  check = function(state) {
    if(inherits(state$namespace, "try-error")) return(na_result())
    check_result(length(state$namespace$exportPatterns) == 0)
  }
)
