Find and Fix Lints in R Code
Create a custom rule for internal use
Require usage of anyDuplicated(x) > 0 over any(duplicated(x))
Require usage of anyNA(x) over any(is.na(x))
Block comparison of class with ==
Block usage of paste() and paste0() with messaging functions using...
double_assignment
Duplicate argument linter
empty_assignment
equal_assignment
Equality check with NA linter
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...
Require usage of expect_named(x, n) over expect_equal(names(x), n)
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), ...
Create a custom rule for external use
Automatically replace lints
flir: Find and Fix Lints in R Code
Block usage of for loops directly overwriting the indexing variable
Lint common mistakes/style issues cropping up from return statements
implicit_assignment
Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x)
Require usage of nlevels over length(levels(.))
Check for a common mistake where length is applied in the wrong place
Require usage of lengths() where possible
Library call linter
List all lints in a file or a directory
Block usage of comparison operators with known-list() functions like l...
Get the list of linters in flir
Require usage of correctly-typed literals over literal coercions
Require usage of colSums(x) or rowSums(x) over apply(x, ., sum)
Missing argument linter
Block usage of nested ifelse() calls
Require usage of a leading zero in all fractional numerics
Require usage of nzchar where appropriate
Require usage of !any(x) over all(!x), !all(x) over any(!x)
Package hooks linter
Raise lints for several common poor usages of paste()
Block usage of ==, != on logical vectors
Prevent ifelse() from being used to produce TRUE/FALSE or 1/`0...
Require usage of rep_len(x, n) over rep(x, length.out = n)
right_assignment
Require usage of sample.int(n, m, ...) over sample(1:n, m, ...)
Sequence linter
Create a Github Actions workflow for flir
Setup flir
Check for common mistakes around sorting vectors
Block usage of all() within stopifnot()
T and F symbol linter
TODO comment linter
Undesirable function linter
Undesirable operator linter
Block instances of unnecessary nesting
Enforce usage of scalar logical operators in conditional statements
Require usage of grep over which(grepl(.))
Lints are code patterns that are not optimal because they are inefficient, forget corner cases, or are less readable. 'flir' provides a small set of functions to detect those lints and automatically fix them. It builds on 'astgrepr', which itself uses the 'Rust' crate 'ast-grep' to parse and navigate R code.
Useful links