Skip to contents

Assignment of {} is the same as assignment of NULL; use the latter for clarity. Closely related: unnecessary_concatenation_linter().

Usage

empty_assignment_linter()

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "x <- {}",
  linters = empty_assignment_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size.

writeLines("x = {\n}")
#> x = {
#> }
lint(
  text = "x = {\n}",
  linters = empty_assignment_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size.

# okay
lint(
  text = "x <- { 3 + 4 }",
  linters = empty_assignment_linter()
)

lint(
  text = "x <- NULL",
  linters = empty_assignment_linter()
)