Code linting - REditorSupport/vscode-R GitHub Wiki
R code linting (diagnostics) is provided by lintr via language server and is enabled by default. It provides syntax error warnings as well as style guidelines.
To disable diagnostics, you might add the following to the VS Code settings:
{
"r.lsp.diagnostics": false
}
However, you will not be notified if syntax errors in the code are detected.
Customize
The default linting behaviour is based on the tidyverse
style guide, which you may not find to your liking. To customize, you should create/edit the global lintr config file at ~/.lintr
. Alternatively, you can also create/edit a project-specific lintr config file at ${workspaceFolder}/.lintr
. Some example of customized lintr files are provided below.
- Visit Individual linters for a complete list of supported linters.
- Visit the Configuring linters for a complete guide to customizing lintr config regarding the list of linters and file or line exclusions.
Examples
Only detect syntax errors:
linters: list()
default linters:
Deviate fromAdjust the number of characters in each line for line_length_linter
and disable commented_code_linter
.
linters: linters_with_defaults(
line_length_linter(120),
commented_code_linter = NULL
)
A more aggressive example, turning off the <-
assignment linter (i.e., =
is fine) among other things. Background here.
linters: linters_with_defaults(
line_length_linter = NULL, # note: vscode-R default is 120
cyclocomp_linter = NULL, # same as vscode-R
object_name_linter = NULL, # same as vscode-R
object_usage_linter = NULL, # same as vscode-R
commented_code_linter = NULL,
assignment_linter = NULL,
single_quotes_linter = NULL,
semicolon_linter = NULL,
seq_linter = NULL,
indentation_linter = NULL
)
Only use specified linters:
linters: list(
commas_linter(),
duplicate_argument_linter(),
missing_argument_linter(),
missing_package_linter(),
namespace_linter())