Last active
February 11, 2021 16:38
-
-
Save Kuret/8e0e827367a16cd1f2ab71848bc65967 to your computer and use it in GitHub Desktop.
Git Hooks for Elixir/Phoenix/Webpack
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
#!/bin/bash | |
# Runs ESLint and Stylelint on all STAGED files before committing | |
js_files=$(git diff --cached --name-status | grep '^\(A\|M\).*\.jsx\?$' | sed 's/^[AM]//g') | |
css_files=$(git diff --cached --name-status | grep '^\(A\|M\).*\.cssx\?$' | sed 's/^[AM]//g') | |
# Prevent ESLint help message if no files matched | |
if [ "${js_files}" = "" ] && [ "${css_files}" = "" ] ; then | |
exit 0 | |
fi | |
failed=0 | |
for jsfile in ${js_files}; do | |
git show :$jsfile | npx eslint --stdin --stdin-filename $jsfile | |
if [[ $? != 0 ]] ; then | |
failed=1 | |
fi | |
done; | |
for cssfile in ${css_files}; do | |
git show :$cssfile | npx stylelint --stdin --stdin-filename $cssfile | |
if [[ $? != 0 ]] ; then | |
failed=1 | |
fi | |
done; | |
if [[ $failed != 0 ]] ; then | |
echo "Lint check failed, commit denied" | |
exit $failed | |
fi |
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
#!/bin/bash | |
# Runs Credo before pushing (not doing this for every commit because it is generally slower) | |
mix credo --strict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment