object_usage_linter: Object usage linter

View source: R/object_usage_linter.R

object_usage_linterR Documentation

Object usage linter

Description

Check that closures have the proper usage using codetools::checkUsage(). Note that this runs base::eval() on the code, so do not use with untrusted code.

Usage

object_usage_linter(
  interpret_glue = NULL,
  interpret_extensions = c("glue", "rlang"),
  skip_with = TRUE
)

Arguments

interpret_glue

(Deprecated) If TRUE, interpret glue::glue() calls to avoid false positives caused by local variables which are only used in a glue expression. Provide interpret_extensions instead, see below.

interpret_extensions

Character vector of extensions to interpret. These are meant to cover known cases where variables may be used in ways understood by the reader but not by checkUsage() to avoid false positives. Currently "glue" and "rlang" are supported, both of which are in the default.

  • For glue, examine glue::glue() calls.

  • For rlang, examine .env$key usages.

skip_with

A logical. If TRUE (default), code in with() expressions will be skipped. This argument will be passed to skipWith argument of codetools::checkUsage().

Linters

The following linters are tagged with 'package_development':

  • backport_linter

  • conjunct_test_linter

  • expect_comparison_linter

  • expect_identical_linter

  • expect_length_linter

  • expect_named_linter

  • expect_not_linter

  • expect_null_linter

  • expect_s3_class_linter

  • expect_s4_class_linter

  • expect_true_false_linter

  • expect_type_linter

  • package_hooks_linter

  • yoda_test_linter

See Also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "foo <- function() { x <- 1 }",
  linters = object_usage_linter()
)

# okay
lint(
  text = "foo <- function(x) { x <- 1 }",
  linters = object_usage_linter()
)

lint(
  text = "foo <- function() { x <- 1; return(x) }",
  linters = object_usage_linter()
)

r-lib/lintr documentation built on June 9, 2025, 7:45 a.m.