Check that no semicolons terminate expressions.
Arguments
- allow_compound
Logical, default
FALSE
. IfTRUE
, "compound" semicolons (e.g. as inx; y
, i.e., on the same line of code) are allowed.- allow_trailing
Logical, default
FALSE
. IfTRUE
, "trailing" semicolons (i.e., those that terminate lines of code) are allowed.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "a <- 1;",
linters = semicolon_linter()
)
#> ::warning file=<text>,line=1,col=7::file=<text>,line=1,col=7,[semicolon_linter] Trailing semicolons are not needed.
lint(
text = "a <- 1; b <- 1",
linters = semicolon_linter()
)
#> ::warning file=<text>,line=1,col=7::file=<text>,line=1,col=7,[semicolon_linter] Compound semicolons are discouraged. Replace them by a newline.
lint(
text = "function() { a <- 1; b <- 1 }",
linters = semicolon_linter()
)
#> ::warning file=<text>,line=1,col=20::file=<text>,line=1,col=20,[semicolon_linter] Compound semicolons are discouraged. Replace them by a newline.
# 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)
#> a <- 1
#> b <- 1
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)
#> function() {
#> a <- 1
#> b <- 1
#> }
lint(
text = code_lines,
linters = semicolon_linter()
)