Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Created June 2, 2022 02:15
Show Gist options
  • Save louisswarren/cd85c3d34822988d0e4871463bc14e34 to your computer and use it in GitHub Desktop.
Save louisswarren/cd85c3d34822988d0e4871463bc14e34 to your computer and use it in GitHub Desktop.
Precommit for linting R
#!/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