Jarl is a fast linter for R: it does static code analysis to search for programming errors, bugs, and suspicious patterns of code.
- Orders of magnitude faster than
lintrandflir1 - Automatic fixes when possible
- Support for 40+ rules (and growing)
- Integration in popular IDEs and editors (VS Code, Positron, Zed, ...)
- CLI available
- Multiple output modes (concise, detailed, JSON format)
- CI workflow
Jarl is built on Air, a fast formatter for R written in Rust.
You can use Jarl manually via the command line, or use extensions to have it integrated in your coding environment.
This shows how to use it in the terminal:
test.R:
any(is.na(x))
if (all.equal(x, y)) {
print("x and y are equal")
}# In the terminal:
$ jarl check test.R
warning: any_is_na
--> test.R:1:1
|
1 | any(is.na(x))
| ------------- `any(is.na(...))` is inefficient.
|
= help: Use `anyNA(...)` instead.
warning: all_equal
--> test.R:3:5
|
3 | if (all.equal(x, y)) {
| --------------- `all.equal()` can return a string instead of FALSE.
|
= help: Wrap `all.equal()` in `isTRUE()`, or replace it by `identical()` if
no tolerance is required.
Found 2 errors.
1 fixable with the `--fix` option (1 hidden fix can be enabled with the
`--unsafe-fixes` option).
Use --fix to automatically fix rule violations when possible:
$ jarl check test.R --fixtest.R:
anyNA(x)
if (all.equal(x, y)) {
print("x and y are equal")
}Either get binaries from the Releases page or install Jarl from the existing installer scripts below.
macOS and Linux:
curl --proto '=https' --tlsv1.2 -LsSf \
https://github.com/etiennebacher/jarl/releases/latest/download/jarl-installer.sh | shWindows:
powershell Set-ExecutionPolicy Bypass -Scope Process -Force; `
iwr https://github.com/etiennebacher/jarl/releases/latest/download/jarl-installer.ps1 | iexIf you use Scoop, you can also install or update Jarl with these commands:
scoop bucket add r-bucket https://github.com/cderv/r-bucket.git
# install
scoop install jarl
# update
scoop update jarlAlternatively, if you have Rust installed, you can get the development version with:
cargo install --git https://github.com/etiennebacher/jarl jarl --profile=releaselintr is the most famous R linter.
It provides dozens of rules related to performance, readibility, formatting, and more.
Jarl is heavily influenced by lintr since most rule definitions come from it.
However, lintr doesn't provide automatic fixes for rule violations, which makes it harder to use.
Its performance also noticeably degrades as the number of files and their length increase.
flir is a relatively novel package.
It uses ast-grep in the background to search and replace code patterns.
It is therefore quite flexible and easy to extend by users who may want more custom rules.
While both Jarl and ast-grep use tree-sitter in the background to parse R files, their structure is completely different.
Jarl is faster and also easier to link to the Language Server Protocol, which enables its use via VS Code or Positron extensions for instance.
lintrauthors and contributors: while the infrastructure is completely different, all the rule definitions and a large part of the tests are inspired or taken fromlintr.- Davis Vaughan and Lionel Henry, both for their work on Air and for their advices and answers to my questions during the development of Jarl.
- the design of Jarl is heavily inspired by Ruff and Cargo clippy.
- R Consortium for funding part of the development of Jarl.
Footnotes
-
Using 20 rules on the
dplyrpackage (~25k lines of R code), Jarl took 0.131s,flirtook 4.5s, andlintrtook 18.5s (9s with caching enabled). ↩
