A 'Linter' for R Code
Require usage of anyDuplicated(x) > 0
over any(duplicated(x))
Require usage of anyNA(x)
over any(is.na(x))
Assignment linter
Block comparison of class with ==
Clear the lintr cache
Commas linter
Commented code linter
Common mistake linters
Block usages like !(x == y) where a direct relational operator is appr...
Force consecutive calls to assertions into just one when possible
Require usage of expect_false(x)
over expect_true(!x)
Require usage of expect_null
for checking NULL
Require usage of expect_s3_class()
Require usage of expect_s4_class(x, k)
over expect_true(is(x, k))
Require usage of expect_true(x)
over expect_equal(x, TRUE)
Require usage of expect_type(x, type)
over `expect_equal(typeof(x), ...
Require usage of fixed=TRUE
in regular expressions where appropriate
Block usage of for loops directly overwriting the indexing variable
Implicit integer linter
Check that indentation is consistent
Object length linter
Pipe continuation linter
Block usage of return() in magrittr pipelines
Testthat linters
Require usage of sample.int(n, m, ...) over sample(1:n, m, ...)
SARIF Report for lint results
Block usage like x %in% "a"
Block usage of all() within stopifnot()
Prohibit close() from terminating a function definition
Tidyverse design linters
TODO comment linter
Trailing blank lines linter
Trailing whitespace linter
Convert an XML node or nodeset into a Lint
Infix spaces linter
Require usage of lengths()
where possible
Library call linter
Line length linter
Create a lint
object
Lint a file, directory, or package
Create a linter
closure
Create a linter configuration based on defaults
Require usage of colSums(x)
or rowSums(x)
over apply(x, ., sum)
Missing argument linter
Missing package linter
Normalize lint exclusions
Block usage of nrow(subset(x, .))
Require usage of a leading zero in all fractional numerics
Require usage of nzchar where appropriate
Require usage of grep over which(grepl(.))
Whitespace linter
Default undesirable functions and operators
Absolute path linter
Create a linter configuration based on all available linters
Deprecated linters
Get Linter metadata from a package
Backport linter
Best practices linters
Require usage of boolean operators over equivalent arithmetic
Brace linter
Checkstyle Report for lint results
Recommend usage of call. = FALSE
in conditions
Block usage of paste()
and paste0()
with messaging functions using...
Configurable linters
Force &&
conditions to be written separately where appropriate
Package development linters
Require consecutive calls to mutate() to be combined when possible
Consistency linters
Correctness linters
Cyclomatic complexity linter
Default linters
Default lintr settings
Duplicate argument linter
Efficiency linters
Block assignment of {}
Equality check with NA linter
Exclude lines or files from linting
Code executing linters
Require usage of expect_gt(x, y)
over expect_true(x > y)
(and simi...
Require usage of expect_identical(x, y)
where appropriate
Require usage of expect_length(x, n)
over `expect_equal(length(x), n...
Test that the package is lint free
Lint expectation
Require usage of expect_named(x, n)
over expect_equal(names(x), n)
Function argument linter
Function left parentheses linter
Lint common mistakes/style issues cropping up from return statements
Extract text from STR_CONST
nodes
Parsed sourced file from a filename
Get parsed IDs by token
Block statements like if (!A) x else y
Require usage of switch() over repeated if/else blocks
Block usage of ifelse()
where pmin()
or pmax()
is more appropria...
Avoid implicit assignment in function calls
Require c()
to be applied before relatively expensive vectorized fun...
Is this an expression- or a file-level source object?
Redirect is.numeric(x) || is.integer(x)
to just use is.numeric(x)
Block unnecessary quoting in calls
Require usage of nlevels over length(levels(.))
Check for a common mistake where length is applied in the wrong place
Create a tag-based linter configuration
Available linters
Deprecated functions in lintr
Lintr
Block usage of comparison operators with known-list() functions like l...
Require usage of correctly-typed literals over literal coercions
Create a linter from an XPath
Modify lintr defaults
Namespace linter
Block usage of nested ifelse()
calls
Block usage of pipes nested inside other calls
Non-portable path linter
Object name linter
Block assigning any variables whose name clashes with a base
R funct...
Object usage linter
Block single-call magrittr pipes
Require usage of !any(x)
over all(!x)
, !all(x)
over any(!x)
Package hooks linter
Parenthesis before body linter
read a source file and parse all the excluded lines from it
Raise lints for several common poor usages of paste()
Pipe call linter
Pipe consistency linter
Identify unregistered native routines
Block usage of print() for logging
Character string quote linter
Read lintr settings
Readability linters
Block usage of ==
, !=
on logical vectors
Prevent ifelse()
from being used to produce TRUE
/FALSE
or 1
/`0...
Regular expression linters
Require usage of direct methods for subsetting strings via regex
Require usage of rep_len(x, n) over rep(x, length.out = n)
Repeat linter
Return linter
Robustness linters
Semicolon linter
Sequence linter
Check for common mistakes around sorting vectors
Spaces inside linter
Spaces before parentheses linter
Require correct sprintf()
calls
Require usage of startsWith()
and endsWith()
over grepl()
/`subst...
Identify cases where stringsAsFactors
should be supplied explicitly
Style linters
Block usage of file.path()
with system.file()
T
and F
symbol linter
Undesirable function linter
Undesirable operator linter
Unneeded concatenation linter
Block usage of anonymous functions in iteration functions when unneces...
Enforce usage of scalar logical operators in conditional statements
Block instances of unnecessary nesting
Block usage of pipeline placeholders if unnecessary
Block unreachable code and comments following return statements
Check that imported packages are actually used
Use lintr in your project
Get the name of the function matched by an XPath
Block obvious "yoda tests"
Checks adherence to a given style, syntax errors and possible semantic issues. Supports on the fly checking of R code edited with 'RStudio IDE', 'Emacs', 'Vim', 'Sublime Text', 'Atom' and 'Visual Studio Code'.
Useful links