Skip to content

Commit 80a12c4

Browse files
feat: add pre-commit hooks for php-cs-fixer and phpunit (#109)
Add php-cs-fixer and phpunit as local pre-commit hooks to ensure code quality and tests pass before commits. Also add a Claude Code session start hook to automatically install pre-commit hooks when starting a new session. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 54c890a commit 80a12c4

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

.claude/hooks/SessionStart.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# Session start hook to ensure pre-commit is installed
4+
echo "Setting up pre-commit..."
5+
6+
# Check if pre-commit is available, install if not
7+
if ! command -v pre-commit &> /dev/null; then
8+
echo "pre-commit is not installed. Installing pre-commit..."
9+
10+
# Try to install pre-commit using pip
11+
if command -v pip3 &> /dev/null; then
12+
pip3 install pre-commit
13+
elif command -v pip &> /dev/null; then
14+
pip install pre-commit
15+
else
16+
echo "Error: pip is not installed. Cannot install pre-commit."
17+
exit 1
18+
fi
19+
20+
# Verify installation
21+
if ! command -v pre-commit &> /dev/null; then
22+
echo "Error: Failed to install pre-commit."
23+
exit 1
24+
fi
25+
26+
echo "pre-commit installed successfully!"
27+
fi
28+
29+
# Install pre-commit hooks
30+
pre-commit install
31+
pre-commit install --hook-type commit-msg
32+
33+
echo "Pre-commit hooks installed successfully!"

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,17 @@ repos:
1313
hooks:
1414
- id: conventional-pre-commit
1515
stages: [commit-msg]
16+
- repo: local
17+
hooks:
18+
- id: php-cs-fixer
19+
name: PHP CS Fixer
20+
entry: vendor/bin/php-cs-fixer fix
21+
language: system
22+
types: [php]
23+
pass_filenames: false
24+
- id: phpunit
25+
name: PHPUnit
26+
entry: vendor/bin/phpunit
27+
language: system
28+
types: [php]
29+
pass_filenames: false

0 commit comments

Comments
 (0)