Skip to contents

folder_findings() reads the config file of the folder path. It runs each rule of the registry rules that the rule set of the config file has, and returns the findings. It does not print and does not quit.

Usage

folder_findings(
  path = ".",
  config = "checkit.yml",
  rules = general_rules(),
  sets = system.file("rules", package = "checkit"),
  scope = default_scope,
  messages = checkit_messages(),
  set_pattern = "^checkit_([0-9]{4})_([0-9]{2})_([0-9]{2})$",
  reserved_ignore = function(set) character(0),
  reserved_rules = character(0)
)

Arguments

path

The project folder.

config

The name of the config file in path. A rule set MAY hold the key packages, a map from the name of a package to its minimum version. It is not a rule. The runner gives it to each rule function that has the argument packages, such as the function of rule_set_pinned.

rules

The registry: a named list of rule() entries, such as compose_rules() gives. The default is general_rules().

sets

The folder of the rule sets. The default is the folder rules of checkit.

scope

A function scope(path, ignore) that returns the named list files that each rule function gets. ignore holds the folders of the key ignore for a rule that is not locked, and is empty for a locked rule. The default is default_scope().

messages

The texts of the config messages, a named list as checkit_messages() gives.

set_pattern

A regular expression that each name of a rule set matches. Its three groups are the year, the month and the day of the set.

reserved_ignore

A function of the name of the set of the project that returns regular expressions. An entry of ignore that one of them matches is an error.

reserved_rules

A named character vector. Each name is a name that the keys rules and allow MUST NOT hold. The error is "<config>: <key>: <name> <value>", so each value is the rest of the message.

Value

A data.frame of the findings with the columns rule, status, path and detail. It has one row for each finding. A rule that runs and finds nothing has one PASS row, and a rule that is off has one OFF row. A SKIP row of a rule stays SKIP at the levels fail and warn, and the key allow does not change it. The detail of each WARN and FAIL ends with ". Fix: <fix>.". The detail of a SKIP has no fix.

Details

The config file holds four keys:

  • extends names a rule set, a file <set>.yml in the folder sets. The set gives each rule a level, fail, warn or off, and its parameters. A rule that the registry has and the set does not have does not run and gives no line.

  • rules changes the level or a parameter of a rule, merged into the entry of the set. A short form such as name: warn changes the level only. The set marks a locked rule with locked: true, and the config file cannot change its level.

  • allow lists paths for each rule. A path covers the findings with that path and with each path under it. A covered finding is WARN, with (allowed) at the end of its detail. A path that covers no finding is a WARN of the rule allow. The config file cannot allow a path for a locked rule.

  • ignore lists top-level folders that no rule reads, other than the locked rules.

The config reader stops before any rule runs on an error in the config file, with a message that names the key.

Examples

home <- file.path(tempdir(), "checkit_findings_example")
dir.create(file.path(home, "rules"), recursive = TRUE)
writeLines("no_capitals: fail", file.path(home, "rules", "demo_2026_01_01.yml"))
writeLines("extends: demo_2026_01_01", file.path(home, "demo.yml"))
writeLines("x", file.path(home, "Notes.txt"))
no_capitals <- checkit::rule(
  fn = function(path, files) {
    bad <- files$entries[grepl("[A-Z]", basename(files$entries))]
    return(data.frame(
      rule = rep("no_capitals", length(bad)),
      status = rep("FAIL", length(bad)),
      path = bad,
      detail = paste0(bad, ": a capital letter in the name", recycle0 = TRUE)
    ))
  },
  pass_detail = "no capital letter in a name",
  fix = "rename it in lower case"
)
checkit::folder_findings(
  home,
  config = "demo.yml",
  rules = list(no_capitals = no_capitals),
  sets = file.path(home, "rules"),
  scope = function(path, ignore) {
    return(list(entries = setdiff(list.files(path), ignore)))
  },
  set_pattern = "^demo_([0-9]{4})_([0-9]{2})_([0-9]{2})$"
)
#>          rule status      path
#> 1 no_capitals   FAIL Notes.txt
#>                                                                   detail
#> 1 Notes.txt: a capital letter in the name. Fix: rename it in lower case.
unlink(home, recursive = TRUE)