Skip to contents

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_reason and the text arguments of that rule. pass_detail, fix and locked_reason replace those of the rule, see rule(). A text argument replaces the default value of that argument of the function of the rule. There are three text arguments:

  • exempt_calls of no_absolute_paths, a character vector of functions. The name of each function is the package that the call names with ::, such as c(utils = "read.csv"). The default is empty. The rule stops when it runs with a function that has no package name.

  • writer of frozen_versions_unchanged, one string.

  • holds of gitexclude_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 key packages of 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 as packages: {checkit: 2026.12.3}. Each FAIL has the path "".

  • lower_case_names: no path of files$entries has a capital letter in its name. The extension of a file does not count, and the paths of files$exempt_paths pass.

  • frozen_versions_unchanged, text argument writer: each manifest of files$frozen matches 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 name writer, the function that writes a manifest. The default of writer is "checkit::freeze()".

  • changelog_with_code: in a git repository, each uncommitted change to a path that the regular expression files$changelog_code matches comes with a change to CHANGELOG.md. Outside git it passes.

  • gitexclude_not_tracked, text argument holds: git tracks no path with gitexclude in its name. holds ends the FAIL detail and tells what such a path holds. Outside git it passes. A rule set SHOULD lock it, and its locked_reason tells why.

  • loc_per_file, parameter limit: each file of files$code has at most limit code lines, as org::loc_per_file() counts them. A file that R cannot parse is a FAIL.

  • cyclomatic_complexity, parameter limit: each function that a top-level assignment of a file of files$code defines scores at most limit, as cyclocomp::cyclocomp() scores it. A function in a list() of a top-level assignment counts too.

  • comment_share, parameter limit: in each file of files$scripts_sorted, the comment lines are at most the share limit of the lines that are not blank. limit is from 0 to 1. A section marker such as # Part 1 ---- is not a comment line.

  • no_environment_variables: no file of files$scripts calls or names Sys.getenv or Sys.setenv.

  • no_local_assign, parameter forbid: no file of files$code uses a construct of forbid. The constructs are local(), assign(), delayedAssign(), assignInNamespace(), assignInMyNamespace(), <<- and ->>.

  • no_escape_hatches: no file of files$scripts_sorted calls suppressWarnings(), suppressMessages(), try(), tryCatch() or withCallingHandlers().

  • no_absolute_paths, text argument exempt_calls: no string of a file of files$code is an absolute path. No call of file.path() or fs::path() in these files starts from a string. The arguments of a call of exempt_calls are 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.

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"