Run full precommit quality checks
/plugin marketplace add jeffweiss/elixir-production/plugin install jeffweiss-elixir-production@jeffweiss/elixir-production--fixhaikuExecutes the production-ready precommit workflow to ensure code quality before commits.
Runs four quality checks in sequence:
/precommit # Run all checks
/precommit --fix # Run checks and auto-fix formatting issues
First verify that required tools are installed:
# Check if credo is in mix.exs
if ! grep -q ':credo' mix.exs; then
echo "❌ Missing dependency: credo"
echo "Add to mix.exs:"
echo ' {:credo, "~> 1.7", only: [:dev, :test], runtime: false}'
exit 1
fi
# Check if styler is in mix.exs
if ! grep -q ':styler' mix.exs; then
echo "❌ Missing dependency: styler"
echo "Add to mix.exs:"
echo ' {:styler, "~> 1.0", only: [:dev, :test], runtime: false}'
exit 1
fi
# Check if styler is configured in .formatter.exs
if [[ -f ".formatter.exs" ]]; then
if ! grep -q 'Styler' .formatter.exs; then
echo "⚠️ Styler not configured in .formatter.exs"
echo "Add: plugins: [Styler]"
fi
fi
Execute each check in order:
echo "🔍 Running precommit checks..."
echo ""
# 1. Compile with warnings as errors
echo "1/4 Compiling..."
if mix compile --warnings-as-errors; then
echo "✅ Compilation passed"
else
echo "❌ Compilation failed with warnings"
exit 1
fi
echo ""
# 2. Format code (with --fix flag) or check formatting
echo "2/4 Formatting..."
if [[ "$1" == "--fix" ]]; then
mix format
echo "✅ Code formatted"
else
if mix format --check-formatted 2>&1 | grep -q "mix format"; then
echo "❌ Code needs formatting. Run: mix format"
exit 1
else
echo "✅ Formatting correct"
fi
fi
echo ""
# 3. Run credo
echo "3/4 Static analysis..."
if mix credo --strict; then
echo "✅ Credo passed"
else
echo "❌ Credo found issues"
exit 1
fi
echo ""
# 4. Run tests
echo "4/4 Running tests..."
if mix test; then
echo "✅ All tests passed"
else
echo "❌ Tests failed"
exit 1
fi
echo ""
echo "✅ All precommit checks passed!"
If all checks pass:
✅ Precommit Checks Complete
All checks passed:
✅ Compilation (0 warnings)
✅ Formatting (all files formatted)
✅ Credo (strict mode)
✅ Tests (X tests, 0 failures)
Ready to commit!
If any check fails:
❌ Precommit Checks Failed
Results:
✅ Compilation
❌ Formatting - 3 files need formatting
Run: mix format
Next steps:
1. Run: mix format
2. Review changes
3. Run /precommit again
With --fix flag:
🔧 Precommit with Auto-Fix
1/4 Compilation... ✅
2/4 Formatting... 🔧 Fixed 3 files
3/4 Static analysis... ✅
4/4 Tests... ✅
Auto-fixed:
- Formatted 3 files
- Run git diff to review changes
✅ All checks passed!
❌ Required dependencies not found
Missing:
- credo: Add {:credo, "~> 1.7", only: [:dev, :test], runtime: false}
- styler: Add {:styler, "~> 1.0", only: [:dev, :test], runtime: false}
After adding to mix.exs, run:
mix deps.get
❌ Compilation Failed
Errors found:
lib/my_app/accounts.ex:42: warning: variable "user" is unused
Fix:
- Remove unused variables or prefix with underscore: _user
- Address all warnings
Run: mix compile --warnings-as-errors
❌ Tests Failed
Failed tests:
1) test create_user/1 creates user (MyApp.AccountsTest)
test/my_app/accounts_test.exs:42
Assertion with == failed
left: "Alice"
right: "Bob"
Fix:
- Review test failure details above
- Fix implementation or update tests
- Run: mix test test/my_app/accounts_test.exs:42
Create .precommit.exs in project root to customize (optional):
[
checks: [
compile: true,
format: true,
credo: true,
test: true
],
# Skip specific checks (not recommended)
skip: []
]
To run automatically before each commit, add to .git/hooks/pre-commit:
#!/bin/bash
set -e
echo "Running precommit checks..."
claude-code /precommit
if [ $? -ne 0 ]; then
echo ""
echo "Precommit checks failed. Commit aborted."
echo "Fix issues and try again, or use --no-verify to skip (not recommended)."
exit 1
fi
Make executable:
chmod +x .git/hooks/pre-commit
mix format on entire codebase periodicallyPrecommit succeeds when:
/review - Comprehensive code review beyond precommit checks/spike - Fast prototyping mode (skips some checks)/spike-migrate - Upgrade SPIKE code to pass precommit