undesirable_operator_linter: Undesirable operator linter

View source: R/undesirable_operator_linter.R

undesirable_operator_linterR Documentation

Undesirable operator linter

Description

Report the use of undesirable operators, e.g. ::: or <<- and suggest an alternative.

Usage

undesirable_operator_linter(
  op = default_undesirable_operators,
  call_is_undesirable = TRUE
)

Arguments

op

Character vector of undesirable operators. Input can be any of three types:

  • Unnamed entries must be a character string specifying an undesirable operator.

  • For named entries, the name specifies the undesirable operator.

    • If the entry is a character string, it is used as a description of why a given operator is undesirable

    • Otherwise, entries should be missing (NA) A generic message that the named operator is undesirable is used if no specific description is provided. Input can also be a list of character strings for convenience.

Defaults to default_undesirable_operators. To make small customizations to this list, use modify_defaults().

call_is_undesirable

Logical, default TRUE. Should lints also be produced for prefix-style usage of the operators provided in op?

Tags

best_practices, configurable, robustness, style

See Also

linters for a complete list of linters available in lintr.

Examples

# defaults for which functions are considered undesirable
names(default_undesirable_operators)

# will produce lints
lint(
  text = "a <<- log(10)",
  linters = undesirable_operator_linter()
)

lint(
  text = "mtcars$wt",
  linters = undesirable_operator_linter(op = c("$" = "As an alternative, use the `[[` accessor."))
)

lint(
  text = "`:::`(utils, hasName)",
  linters = undesirable_operator_linter()
)

lint(
  text = "mtcars$wt",
  linters = undesirable_operator_linter("$")
)

# okay
lint(
  text = "a <- log(10)",
  linters = undesirable_operator_linter()
)
lint(
  text = 'mtcars[["wt"]]',
  linters = undesirable_operator_linter(op = c("$" = NA))
)

lint(
  text = 'mtcars[["wt"]]',
  linters = undesirable_operator_linter(op = c("$" = "As an alternative, use the `[[` accessor."))
)

lint(
  text = "`:::`(utils, hasName)",
  linters = undesirable_operator_linter(call_is_undesirable = FALSE)
)

lint(
  text = 'mtcars[["wt"]]',
  linters = undesirable_operator_linter("$")
)


jimhester/lintr documentation built on June 14, 2025, 1:27 a.m.