mirror of
https://github.com/Cacti/cacti.git
synced 2026-10-23 03:27:02 +09:00
Fixing pre-commit hooks (#6891)
* Fixing pre-commit hooks * Update composer.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
678039bec8
commit
d8d5a944f0
3 files changed
+33
-14
No files matched your search
@@ -3,21 +3,21 @@ repos:
|
||||
hooks:
|
||||
- id: lintcheck
|
||||
name: PHP Lint Checking
|
||||
entry: sh scripts/pre-commit-check.sh lint
|
||||
entry: sh tests/tools/pre-commit-check.sh lint
|
||||
language: system
|
||||
types: [php]
|
||||
always_run: true
|
||||
|
||||
- id: phpcsfixer
|
||||
name: PHP CS Fixer Validation
|
||||
entry: sh scripts/pre-commit-check.sh phpcsfixer
|
||||
entry: sh tests/tools/pre-commit-check.sh phpcsfixer
|
||||
language: system
|
||||
types: [php]
|
||||
always_run: true
|
||||
|
||||
- id: phpstan
|
||||
name: PHPStan Validation
|
||||
entry: sh scripts/pre-commit-check.sh phpstan
|
||||
entry: sh tests/tools/pre-commit-check.sh phpstan
|
||||
language: system
|
||||
types: [php]
|
||||
always_run: true
|
||||
+3
-2
@@ -69,8 +69,9 @@
|
||||
"scripts": {
|
||||
"lint": "phplint --no-cache --exclude=include/vendor ",
|
||||
"phpstan": "phpstan analyse --level 6 ",
|
||||
"phpcsfixer": "php-cs-fixer fix --allow-unsupported-php-version=yes --dry-run --diff --config=./.php-cs-fixer.php ",
|
||||
"phpcsfixit": "php-cs-fixer fix ",
|
||||
"php-cs-fixer": "php-cs-fixer fix --allow-unsupported-php-version=yes --dry-run --diff --config=./.php-cs-fixer.php ",
|
||||
"phpcsfixer": "@php-cs-fixer",
|
||||
"php-cs-fixit": "php-cs-fixer fix ",
|
||||
"test": "include/vendor/bin/pest --display-warnings"
|
||||
},
|
||||
"authors": [
|
||||
|
||||
@@ -27,16 +27,20 @@ check_php_version() {
|
||||
|
||||
check_merge_conflicts() {
|
||||
staged=$(git diff --cached --name-only --diff-filter=ACM -- '*.php')
|
||||
|
||||
if [ -z "$staged" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
conflicts=$(echo "$staged" | xargs grep -l '^<<<<<<<\|^=======$\|^>>>>>>>' 2>/dev/null || true)
|
||||
|
||||
if [ -n "$conflicts" ]; then
|
||||
echo ""
|
||||
echo "ERROR: Merge conflict markers found in staged files:"
|
||||
echo "$conflicts"
|
||||
echo " Resolve conflicts before committing."
|
||||
echo ""
|
||||
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -48,12 +52,14 @@ check_composer_lock() {
|
||||
echo " Cacti supports multiple PHP versions; composer.lock must not be committed."
|
||||
echo " Run: git reset HEAD composer.lock"
|
||||
echo ""
|
||||
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_vendor_dev_deps() {
|
||||
staged_vendor=$(git diff --cached --name-only | grep '^include/vendor/' | head -5)
|
||||
|
||||
if [ -n "$staged_vendor" ]; then
|
||||
echo ""
|
||||
echo "WARNING: Vendor files are staged for commit:"
|
||||
@@ -61,22 +67,22 @@ check_vendor_dev_deps() {
|
||||
echo " Dev dependencies should not be committed to include/vendor/."
|
||||
echo " Run: git reset HEAD include/vendor/"
|
||||
echo ""
|
||||
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_autoload_freshness() {
|
||||
if [ -f composer.json ] && [ -f include/vendor/autoload.php ]; then
|
||||
if [ composer.json -nt include/vendor/autoload.php ]; then
|
||||
echo "WARNING: composer.json is newer than vendor/autoload.php."
|
||||
echo " Run: composer install --ignore-platform-reqs"
|
||||
fi
|
||||
if [ ! -f include/vendor/autoload.php ]; then
|
||||
echo "WARNING: your are missing the composer autoload. Please run composer install"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_tool() {
|
||||
tool="$1"
|
||||
label="$2"
|
||||
|
||||
if [ ! -x "$VENDOR_BIN/$tool" ]; then
|
||||
echo ""
|
||||
echo "ERROR: $label not found at $VENDOR_BIN/$tool"
|
||||
@@ -86,15 +92,18 @@ check_tool() {
|
||||
echo " Dev dependencies must be installed for pre-commit hooks."
|
||||
echo " This is a one-time setup after cloning or switching branches."
|
||||
echo ""
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify the tool can actually load (catches missing Symfony/autoload issues)
|
||||
if ! "$VENDOR_BIN/$tool" --version > /dev/null 2>&1; then
|
||||
if [ $($VENDOR_BIN/$tool --version > /dev/null 2>&1) -gt 0 ]; then
|
||||
echo ""
|
||||
echo "ERROR: $label exists but failed to load. Autoload may be stale."
|
||||
echo ""
|
||||
echo " Run: composer install --ignore-platform-reqs"
|
||||
echo ""
|
||||
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -102,37 +111,46 @@ check_tool() {
|
||||
# ---- Lint / analysis tools ----
|
||||
|
||||
run_lint() {
|
||||
if [ -x "$VENDOR_BIN/phplint" ] && "$VENDOR_BIN/phplint" --version > /dev/null 2>&1; then
|
||||
if [ -x "$VENDOR_BIN/phplint" ] && [ $("$VENDOR_BIN/phplint" --version > /dev/null 2>&1) -gt 0 ]; then
|
||||
echo "Running PHP lint (phplint)..."
|
||||
|
||||
composer run-script lint
|
||||
else
|
||||
echo "phplint not available or broken, falling back to php -l on staged files..."
|
||||
|
||||
staged=$(git diff --cached --name-only --diff-filter=ACM -- '*.php')
|
||||
|
||||
if [ -z "$staged" ]; then
|
||||
echo " No staged PHP files to check."
|
||||
return 0
|
||||
fi
|
||||
|
||||
fail=0
|
||||
|
||||
for f in $staged; do
|
||||
if ! php -l "$f" > /dev/null 2>&1; then
|
||||
php -l "$f"
|
||||
fail=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$fail" -eq 1 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " All staged PHP files pass syntax check."
|
||||
fi
|
||||
}
|
||||
|
||||
run_phpcsfixer() {
|
||||
check_tool "php-cs-fixer" "PHP CS Fixer"
|
||||
|
||||
echo "Running PHP CS Fixer (dry-run)..."
|
||||
if ! composer run-script phpcsfixer; then
|
||||
|
||||
if [ $(composer run-script php-cs-fixer) -gt 0 ]; then
|
||||
echo ""
|
||||
echo "TIP: To auto-fix formatting issues, run:"
|
||||
echo " composer run-script phpcsfixit"
|
||||
echo " composer run-script php-cs-fixit"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
Reference in new issue
Block a user