Created
August 9, 2023 14:00
-
-
Save russHyde/cdb6e5b5ee70f31a8a8b4eb6aabc63d0 to your computer and use it in GitHub Desktop.
Local lintr hook for pre-commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An issue with the lintr pre-commit hook is that packages are not fully loaded | |
# prior to linting, so you can get lots of object-usage lints when an object from | |
# your dev packages namespace is used. | |
# | |
# The following ensures your dev package is loaded before linting the changed | |
# files within it. It requires {lintr} to be installed in your dev environment. | |
# This differs from most pre-commit hooks (which usually run in a hook-specific | |
# renv environment) | |
# | |
# All available hooks: https://pre-commit.com/hooks.html | |
# R specific hooks: https://github.com/lorenzwalthert/precommit | |
repos: | |
- repo: local | |
hooks: | |
- id: local-lintr | |
name: Run lintr with global R environment | |
entry: > | |
Rscript -e "pkgload::load_all(); | |
output <- commandArgs(trailingOnly=TRUE) |> strsplit(' ') |> | |
unlist() |> lapply(lintr::lint) |> purrr::compact(); | |
if (length(output) > 0) {print(output); stop('Files not lint free')}" | |
language: system | |
files: '(\.[rR]profile|\.R|\.Rmd|\.Rnw|\.r|\.rmd|\.rnw)$' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on lorenzwalthert/precommit#440 (comment)