general_rules() returns the registry of the rules of checkit that apply
to any project. The argument texts replaces the texts of named rules, so
that another package can give its own words.
Usage
general_rules(texts = list())Arguments
- texts
A list named by the names of rules. Each element is a named list with one or more of
pass_detail,fix,locked_reasonand the text arguments of that rule.pass_detail,fixandlocked_reasonreplace those of the rule, seerule(). A text argument replaces the default value of that argument of the function of the rule. There are three text arguments:exempt_callsofno_absolute_paths, a character vector of functions. The name of each function is the package that the call names with::, such asc(utils = "read.csv"). The default is empty. The rule stops when it runs with a function that has no package name.writeroffrozen_versions_unchanged, one string.holdsofgitexclude_not_tracked, one string. The default is"data that git MUST NOT track".
Value
A named list of rule() entries.
Details
Each rule reads the files that the scope gives, see the argument scope
of folder_findings() and default_scope(). Each rule parses each file
and runs no code of it. The 12 rules, in the order of the registry:
rule_set_pinned: each package of the keypackagesof the rule set of the project is installed, at its minimum version or newer. The key maps the name of each package to its minimum version, such aspackages: {checkit: 2026.12.3}. Each FAIL has the path"".lower_case_names: no path offiles$entrieshas a capital letter in its name. The extension of a file does not count, and the paths offiles$exempt_pathspass.frozen_versions_unchanged, text argumentwriter: each manifest offiles$frozenmatches the files that it covers. A required manifest that is absent is a FAIL. So is a manifest line that is not"<md5> <path>", and each file that changed, was removed or was added after the manifest was written. The details namewriter, the function that writes a manifest. The default ofwriteris"checkit::freeze()".changelog_with_code: in a git repository, each uncommitted change to a path that the regular expressionfiles$changelog_codematches comes with a change toCHANGELOG.md. Outside git it passes.gitexclude_not_tracked, text argumentholds: git tracks no path withgitexcludein its name.holdsends the FAIL detail and tells what such a path holds. Outside git it passes. A rule set SHOULD lock it, and itslocked_reasontells why.loc_per_file, parameterlimit: each file offiles$codehas at mostlimitcode lines, asorg::loc_per_file()counts them. A file that R cannot parse is a FAIL.cyclomatic_complexity, parameterlimit: each function that a top-level assignment of a file offiles$codedefines scores at mostlimit, ascyclocomp::cyclocomp()scores it. A function in alist()of a top-level assignment counts too.comment_share, parameterlimit: in each file offiles$scripts_sorted, the comment lines are at most the sharelimitof the lines that are not blank.limitis from 0 to 1. A section marker such as# Part 1 ----is not a comment line.no_environment_variables: no file offiles$scriptscalls or namesSys.getenvorSys.setenv.no_local_assign, parameterforbid: no file offiles$codeuses a construct offorbid. The constructs arelocal(),assign(),delayedAssign(),assignInNamespace(),assignInMyNamespace(),<<-and->>.no_escape_hatches: no file offiles$scripts_sortedcallssuppressWarnings(),suppressMessages(),try(),tryCatch()orwithCallingHandlers().no_absolute_paths, text argumentexempt_calls: no string of a file offiles$codeis an absolute path. No call offile.path()orfs::path()in these files starts from a string. The arguments of a call ofexempt_callsare exempt.
A text argument is an argument of the function of a rule that has a
default value. The rule functions are internal, and
general_rules()[[name]]$fn gives each one. The function of
rule_set_pinned has the argument packages, and the runner gives it the
key packages of the rule set.
See also
Other runner:
check_folder(),
checkit_messages(),
compose_rules(),
default_scope(),
folder_findings(),
folder_report(),
rule(),
rules()
Examples
names(checkit::general_rules())
#> [1] "rule_set_pinned" "lower_case_names"
#> [3] "frozen_versions_unchanged" "changelog_with_code"
#> [5] "gitexclude_not_tracked" "loc_per_file"
#> [7] "cyclomatic_complexity" "comment_share"
#> [9] "no_environment_variables" "no_local_assign"
#> [11] "no_escape_hatches" "no_absolute_paths"
own <- checkit::general_rules(list(
no_absolute_paths = list(
fix = "build each path from the folder argument",
exempt_calls = c(utils = "read.csv")
)
))
own$no_absolute_paths$fix
#> [1] "build each path from the folder argument"