Learn R Programming

lintr (version 3.1.2)

semicolon_linter: Semicolon linter

Description

Check that no semicolons terminate expressions.

Usage

semicolon_linter(allow_compound = FALSE, allow_trailing = FALSE)

Arguments

allow_compound

Logical, default FALSE. If TRUE, "compound" semicolons (e.g. as in x; y, i.e., on the same line of code) are allowed.

allow_trailing

Logical, default FALSE. If TRUE, "trailing" semicolons (i.e., those that terminate lines of code) are allowed.

Tags

configurable, default, readability, style

See Also

Examples

Run this code
# will produce lints
lint(
  text = "a <- 1;",
  linters = semicolon_linter()
)

lint(
  text = "a <- 1; b <- 1",
  linters = semicolon_linter()
)

lint(
  text = "function() { a <- 1; b <- 1 }",
  linters = semicolon_linter()
)

# okay
lint(
  text = "a <- 1",
  linters = semicolon_linter()
)

lint(
  text = "a <- 1;",
  linters = semicolon_linter(allow_trailing = TRUE)
)

code_lines <- "a <- 1\nb <- 1"
writeLines(code_lines)
lint(
  text = code_lines,
  linters = semicolon_linter()
)

lint(
  text = "a <- 1; b <- 1",
  linters = semicolon_linter(allow_compound = TRUE)
)

code_lines <- "function() { \n  a <- 1\n  b <- 1\n}"
writeLines(code_lines)
lint(
  text = code_lines,
  linters = semicolon_linter()
)

Run the code above in your browser using DataLab