R/check_codemeta.R

Defines functions check_codemeta

Documented in check_codemeta

#' Check the package metadata
#'
#' Use the checks from [codemetar::give_opinions()].
#' @inheritParams read_checklist
#' @return A `checklist` object.
#' @importFrom assertthat assert_that
#' @importFrom codemetar give_opinions
#' @importFrom gert git_status
#' @importFrom withr defer
#' @export
#' @family package
check_codemeta <- function(x = ".") {
  x <- read_checklist(x = x)
  assert_that(
    x$package,
    msg = "`check_codemeta()` is only relevant for packages.
`checklist.yml` indicates this is not a package."
  )

  repo <- x$get_path
  status_before <- git_status(repo = repo)
  old_wd <- getwd()
  defer(setwd(old_wd))
  setwd(x$get_path)
  opinions <- give_opinions(x$get_path)
  x$add_error(
    "Code metadata needs to be updated. Run `codemetar::write_codemeta()`."[
      !unchanged_repo(repo, status_before)
    ],
    item = "codemeta", keep = FALSE
  )
  x$add_notes(
    sprintf("in %s fix %s", opinions$where, opinions$fixme), "codemeta"
  )

  return(x)
}
inbo/checklist documentation built on June 15, 2025, 12:54 p.m.