Last active
September 2, 2020 11:19
-
-
Save kevmoo/f1a104e31a4ba6092349 to your computer and use it in GitHub Desktop.
Pre-commit hook to format Dart code
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
# Inspired by https://robots.thoughtbot.com/use-git-hooks-to-automate-annoying-tasks | |
dart_files=$(git diff --cached --name-only --diff-filter=ACM | grep '.dart$') | |
[ -z "$dart_files" ] && exit 0 | |
function checkfmt() { | |
unformatted=$(dartfmt -n $dart_files) | |
[ -z "$unformatted" ] && return 0 | |
echo >&2 "Dart files must be formatted with dartfmt. Please run:" | |
for fn in $unformatted; do | |
echo >&2 " dartfmt -w $PWD/$fn" | |
done | |
return 1 | |
} | |
checkfmt || fail=yes | |
[ -z "$fail" ] || exit 1 | |
echo 'all okay?' | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment