Created
June 2, 2022 02:15
-
-
Save louisswarren/cd85c3d34822988d0e4871463bc14e34 to your computer and use it in GitHub Desktop.
Precommit for linting R
This file contains hidden or 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
#!/bin/bash | |
# | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=$(git hash-object -t tree /dev/null) | |
fi | |
# Redirect output to stderr. | |
exec 1>&2 | |
git diff --cached --name-only --diff-filter=AM -z $against | while IFS= read -r -d $'\0' x; do | |
if [ "${x: -2}" = ".R" ]; then | |
Rscript --no-save --no-restore --no-site-file --no-environ -e "lintr::lint('$x')" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment