Check that there are no space characters at the end of source lines.
Arguments
- allow_empty_lines
Suppress lints for lines that contain only whitespace.
- allow_in_strings
Suppress lints for trailing whitespace in string constants.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "x <- 1.2 ",
linters = trailing_whitespace_linter()
)
#> ::warning file=<text>,line=1,col=9::file=<text>,line=1,col=9,[trailing_whitespace_linter] Trailing whitespace is superfluous.
code_lines <- "a <- TRUE\n \nb <- FALSE"
writeLines(code_lines)
#> a <- TRUE
#>
#> b <- FALSE
lint(
text = code_lines,
linters = trailing_whitespace_linter()
)
#> ::warning file=<text>,line=2,col=1::file=<text>,line=2,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
# okay
lint(
text = "x <- 1.2",
linters = trailing_whitespace_linter()
)
lint(
text = "x <- 1.2 # comment about this assignment",
linters = trailing_whitespace_linter()
)
code_lines <- "a <- TRUE\n \nb <- FALSE"
writeLines(code_lines)
#> a <- TRUE
#>
#> b <- FALSE
lint(
text = code_lines,
linters = trailing_whitespace_linter(allow_empty_lines = TRUE)
)