Skip to content

Commit 3074622

Browse files
committed
r-lintr: add lintr support
1 parent 341ec1d commit 3074622

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

.pre-commit-hooks.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,13 @@
8282
files: (?i)\.R$
8383
pass_filenames: true
8484
minimum_pre_commit_version: 0.15.0
85-
description: 'Run stylr to format R code'
85+
description: 'Run stylr to format R code'
86+
87+
- id: r-lintr
88+
name: 'Analyse with lintr'
89+
entry: run-r-lintr.R
90+
language: 'script'
91+
files: (?i)\.R$
92+
pass_filenames: true
93+
minimum_pre_commit_version: 0.15.0
94+
description: 'Run lintr against R code'

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Hooks:
1414
without forcing the `--fix` argument
1515
* `rust-clippy`: runs `cargo clippy` lints in the repo root
1616
* `r-stylr`: runs [`stylr`] to format R code
17+
* `r-lintr`: static analysis of R code with [`lintr`]
1718

1819
## Example config
1920

@@ -60,6 +61,9 @@ repos:
6061

6162
- id: r-stylr
6263
stages: [commit, push]
64+
65+
- id: r-lintr
66+
stages: [commit, push]
6367
```
6468
6569
## Tagged TODOs
@@ -98,4 +102,5 @@ When adding new hooks you can run `pre-commit try-repo .` for a quick syntax che
98102
[`pre-commit`]: https://pre-commit.com
99103
[dep]: https://github.com/golang/dep
100104
[`post-checkout`]: https://git-scm.com/docs/githooks#_post_checkout
101-
[`stylr`]: https://styler.r-lib.org/
105+
[`stylr`]: https://styler.r-lib.org/
106+
[`lintr`]: https://github.com/jimhester/lintr

run-r-lintr.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env Rscript
2+
3+
files <- commandArgs(trailingOnly=TRUE)
4+
tryCatch(
5+
{
6+
for (f in files) {
7+
lintr::lint(f)
8+
}
9+
},
10+
warning = function(w) stop(conditionMessage(w), call. = FALSE)
11+
)

0 commit comments

Comments
 (0)