rules() prints each rule of the set that the config file of home
extends, in the order of the registry rules. It runs no rule and reads
no other file of the project.
Usage
rules(
home = ".",
config = "checkit.yml",
rules = general_rules(),
sets = system.file("rules", package = "checkit"),
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
- home
The top folder of the project. The default
"."is the working directory.- config
The name of the config file in
path. A rule set MAY hold the keypackages, 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 argumentpackages, such as the function ofrule_set_pinned.- rules
The registry: a named list of
rule()entries, such ascompose_rules()gives. The default isgeneral_rules().- sets
The folder of the rule sets. The default is the folder
rulesof checkit.- 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
ignorethat one of them matches is an error.- reserved_rules
A named character vector. Each name is a name that the keys
rulesandallowMUST NOT hold. The error is"<config>: <key>: <name> <value>", so each value is the rest of the message.
Value
A data.frame, invisibly, with one row for each rule and the
columns rule, level, needs, fix and parameters. parameters
is "" for a rule without parameters. A set with no rule of the
registry gives zero rows.
Details
The first line is the line of the rules of check_folder(). Then, for
each rule, rules() prints these items:
the name, and the level after the changes of the config file;
needs: the text of the PASS line;parameters: the parameters, for a rule that has them;fix: the fix of a finding.
When the fix is a function of the detail of a finding, rules() calls it
with the detail "" and shows the text it returns.
Examples
home <- file.path(tempdir(), "checkit_rules_example")
dir.create(file.path(home, "rules"), recursive = TRUE)
writeLines(
c("no_capitals:", " level: warn", " max: 3"),
file.path(home, "rules", "demo_2026_01_01.yml")
)
writeLines("extends: demo_2026_01_01", file.path(home, "demo.yml"))
no_capitals <- checkit::rule(
fn = function(path, files, max) {
return(data.frame(
rule = character(0),
status = character(0),
path = character(0),
detail = character(0)
))
},
pass_detail = "no capital letter in a name",
fix = "rename it in lower case"
)
checkit::rules(
home,
config = "demo.yml",
rules = list(no_capitals = no_capitals),
sets = file.path(home, "rules"),
set_pattern = "^demo_([0-9]{4})_([0-9]{2})_([0-9]{2})$"
)
#> Rules: demo_2026_01_01, 0 overrides, 0 allowed paths (demo.yml)
#>
#> no_capitals (WARN)
#> needs: no capital letter in a name
#> parameters: max: 3
#> fix: rename it in lower case
unlink(home, recursive = TRUE)