assignment_linter: Assignment linter

View source: R/assignment_linter.R

assignment_linterR Documentation

Assignment linter

Description

Check that the specified operator is used for assignment.

Usage

assignment_linter(
  operator = c("<-", "<<-"),
  allow_cascading_assign = NULL,
  allow_right_assign = NULL,
  allow_trailing = TRUE,
  allow_pipe_assign = NULL
)

Arguments

operator

Character vector of valid assignment operators. Defaults to allowing ⁠<-⁠ and ⁠<<-⁠; other valid options are =, ⁠->⁠, ⁠->>⁠, ⁠%<>%⁠; use "any" to denote "allow all operators", in which case this linter only considers allow_trailing for generating lints.

allow_cascading_assign, allow_right_assign, allow_pipe_assign

(Defunct)

allow_trailing

Logical, default TRUE. If FALSE then assignments aren't allowed at end of lines.

Tags

configurable, consistency, default, style

See Also

Examples

# will produce lints
lint(
  text = "x = mean(x)",
  linters = assignment_linter()
)

code_lines <- "1 -> x\n2 ->> y"
writeLines(code_lines)
lint(
  text = code_lines,
  linters = assignment_linter()
)

lint(
  text = "x %<>% as.character()",
  linters = assignment_linter()
)

lint(
  text = "x <- 1",
  linters = assignment_linter(operator = "=")
)

# okay
lint(
  text = "x <- mean(x)",
  linters = assignment_linter()
)

code_lines <- "x <- 1\ny <<- 2"
writeLines(code_lines)
lint(
  text = code_lines,
  linters = assignment_linter()
)

# customizing using arguments
code_lines <- "1 -> x\n2 ->> y"
writeLines(code_lines)
lint(
  text = code_lines,
  linters = assignment_linter(operator = "->")
)

lint(
  text = "x <<- 1",
  linters = assignment_linter(operator = "<-")
)

writeLines("foo(bar = \n 1)")
lint(
  text = "foo(bar = \n 1)",
  linters = assignment_linter(allow_trailing = FALSE)
)

lint(
  text = "x %<>% as.character()",
  linters = assignment_linter(operator = "%<>%")
)

lint(
  text = "x = 1",
  linters = assignment_linter(operator = "=")
)


r-lib/lintr documentation built on Feb. 28, 2025, 10:08 p.m.