Skip to contents

Cast an S3-object of class "checkglobals" to SARIF json.

Usage

# S3 method for class 'checkglobals'
as_sarif_json(x, path, pattern, which = c("global", "import"), ...)

Arguments

x

object inheriting from class "checkglobals".

path

(optional) file path to write the SARIF json content. If missing, the SARIF content is returned as an object of class json.

pattern

an optional regular expression. Only names matching pattern are returned. glob2rx can be used to convert wildcard patterns to regular expressions.

which

a character vector, either "global" to print all unrecognized global variables, "import" to print all detected imported functions and variables, or both (default).

...

additional arguments to configure the output:

  • all.names, a logical value. If TRUE, all object names are returned. If FALSE, names which begin with a . are omitted. Defaults to TRUE.

  • pretty, a logical value passed to jsonlite::toJSON. Defaults to FALSE.

  • root_dir, directory to use as root relative to which all result uri's are generated.

  • use_cli, a logical value indicating if cli should be used to format the result messages. Defaults to TRUE, which means that cli-formatting is attempted if cli is installed.

  • markdown, a logical value indicating if markdown result fields should be included. Defaults to FALSE.

  • first_only, a logical value to include only the first detected location of an unknown global variable or function (instead of all detected locations). Defaults to FALSE.

Value

if path is provided writes the SARIF json content to path and returns the path invisibly, otherwise returns the SARIF json content as a json object..

Examples

## R-package from folder
chk <- checkglobals(
  pkg = system.file(
    "unit_tests", "pkg", "testpkg",
    package = "checkglobals"
  )
)
json <- as_sarif_json(chk, pretty = TRUE, markdown = TRUE)