lint()
lints a single file.lint_dir()
lints all files in a directory.lint_package()
lints all likely locations for R files in a package, i.e.R/
,tests/
,inst/
,vignettes/
,data-raw/
,demo/
, andexec/
.
Usage
lint(
filename,
linters = NULL,
...,
cache = FALSE,
parse_settings = TRUE,
text = NULL
)
lint_dir(
path = ".",
...,
relative_path = TRUE,
exclusions = list("renv", "packrat"),
pattern = "(?i)[.](r|rmd|qmd|rnw|rhtml|rrst|rtex|rtxt)$",
parse_settings = TRUE,
show_progress = NULL
)
lint_package(
path = ".",
...,
relative_path = TRUE,
exclusions = list("R/RcppExports.R"),
parse_settings = TRUE,
show_progress = NULL
)
Arguments
- filename
Either the filename for a file to lint, or a character string of inline R code for linting. The latter (inline data) applies whenever
filename
has a newline character (\n).- linters
A named list of linter functions to apply. See linters for a full list of default and available linters.
- ...
Provide additional arguments to be passed to:
exclude()
(in case oflint()
; e.g.lints
orexclusions
)lint()
(in case oflint_dir()
andlint_package()
; e.g.linters
orcache
)
- cache
When logical, toggle caching of lint results. I1f passed a character string, store the cache in this directory.
- parse_settings
Logical, default
TRUE
. Whether to try and parse the settings; otherwise, thedefault_settings()
are used.- text
Optional argument for supplying a string or lines directly, e.g. if the file is already in memory or linting is being done ad hoc.
- path
For the base directory of the project (for
lint_dir()
) or package (forlint_package()
).- relative_path
if
TRUE
, file paths are printed using their path relative to the base directory. IfFALSE
, use the full absolute path.- exclusions
exclusions for
exclude()
, relative to the package path.- pattern
pattern for files, by default it will take files with any of the extensions .R, .Rmd, .qmd, .Rnw, .Rhtml, .Rrst, .Rtex, .Rtxt allowing for lowercase r (.r, ...).
- show_progress
Logical controlling whether to show linting progress with a simple text progress bar via
utils::txtProgressBar()
. The default behavior is to show progress ininteractive()
sessions not running a testthat suite.
Details
Read vignette("lintr")
to learn how to configure which linters are run
by default.
Note that if files contain unparseable encoding problems, only the encoding problem will be linted to avoid
unintelligible error messages from other linters.
Examples
f <- withr::local_tempfile(lines = "a=1", fileext = "R")
lint(f) # linting a file
#> Warning: cannot open file '/tmp/RtmpAx0Ma8/file181345b5b25aR': No such file or directory
#> Error in file(con, "r"): cannot open the connection
lint("a = 123\n") # linting inline-code
#> ::warning file=<text>,line=1,col=3::file=<text>,line=1,col=3,[assignment_linter] Use <-, not =, for assignment.
lint(text = "a = 123") # linting inline-code
#> ::warning file=<text>,line=1,col=3::file=<text>,line=1,col=3,[assignment_linter] Use <-, not =, for assignment.
if (FALSE) {
lint_dir()
lint_dir(
linters = list(semicolon_linter()),
exclusions = list(
"inst/doc/creating_linters.R" = 1,
"inst/example/bad.R",
"renv"
)
)
}
if (FALSE) {
lint_package()
lint_package(
linters = linters_with_defaults(semicolon_linter = semicolon_linter()),
exclusions = list("inst/doc/creating_linters.R" = 1, "inst/example/bad.R")
)
}