Created
December 10, 2024 12:30
-
-
Save rdlu/19bcd611d7e7ce6bc08930e27c493fea to your computer and use it in GitHub Desktop.
Simple Elixir/Phoenix pre-commit hook
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/sh | |
# Get staged Elixir files | |
STAGED_FILES=$(git diff --cached --name-only -- '*.ex' '*.exs' '*.heex' '*.eex') | |
if [ -z "$STAGED_FILES" ]; then | |
echo "No Elixir files to check." | |
exit 0 | |
fi | |
# Run mix format on staged files | |
echo "Running mix format on staged files..." | |
mix format $STAGED_FILES | |
# Check if mix format made any changes | |
if git diff --name-only -- '*.ex' '*.exs' '*.heex' '*.eex'; then | |
echo "❌ Code formatting issues found. Please stage the formatted files and try again." | |
exit 1 | |
fi | |
# Run mix credo diff on staged files | |
echo "Running mix credo diff on staged files..." | |
mix credo diff --from-git-ref HEAD | |
if [ $? -ne 0 ]; then | |
echo "❌ Credo found issues that need to be fixed." | |
exit 1 | |
fi | |
echo "✅ All checks passed!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment