Skip to content

Instantly share code, notes, and snippets.

@russHyde
Created August 9, 2023 14:00
Show Gist options
  • Save russHyde/cdb6e5b5ee70f31a8a8b4eb6aabc63d0 to your computer and use it in GitHub Desktop.
Save russHyde/cdb6e5b5ee70f31a8a8b4eb6aabc63d0 to your computer and use it in GitHub Desktop.
Local lintr hook for pre-commit
# 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)$'
@russHyde
Copy link
Author

russHyde commented Aug 9, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment