81 lines
2.1 KiB
Bash
Executable File
81 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
. "$(dirname "$0")/_/husky.sh"
|
|
|
|
# Run JS/CSS checks
|
|
.husky/pre-commit-js-css
|
|
if [ $? -ne 0 ]; then
|
|
echo "JS/CSS checks failed"
|
|
exit 1
|
|
fi
|
|
|
|
# Get the list of staged PHP files
|
|
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.php$')
|
|
|
|
# If there are no staged PHP files, exit
|
|
if [ -z "$STAGED_FILES" ]; then
|
|
echo "No PHP files staged for commit."
|
|
exit 0
|
|
fi
|
|
|
|
# Function to display errors
|
|
display_errors() {
|
|
local errors="$1"
|
|
echo "Errors detected:"
|
|
echo "---------------------------------------"
|
|
echo "$errors" | while IFS='|' read -r file line error; do
|
|
printf "%-60s | %-10s | %s\n" "$file" "$line" "$error"
|
|
done
|
|
echo "---------------------------------------"
|
|
}
|
|
|
|
# Run PHP lint to check for syntax errors
|
|
SYNTAX_ERRORS=0
|
|
echo "Checking PHP syntax errors..."
|
|
for FILE in $STAGED_FILES; do
|
|
php -l "$FILE"
|
|
if [ $? -ne 0 ]; then
|
|
SYNTAX_ERRORS=1
|
|
fi
|
|
done
|
|
|
|
if [ $SYNTAX_ERRORS -ne 0 ]; then
|
|
echo "Syntax errors detected. Please fix them before committing."
|
|
exit 1
|
|
fi
|
|
|
|
# Run PHP CS Fixer to auto-fix issues
|
|
echo "Running PHP CS Fixer..."
|
|
for FILE in $STAGED_FILES; do
|
|
/home/aissel/.config/composer/vendor/bin/php-cs-fixer fix "$FILE"
|
|
done
|
|
|
|
|
|
|
|
# Run PHPCS to check for unresolv//cheks for the file path & the nampespaceed coding standard violations
|
|
echo "Running PHPCS..."
|
|
ERROR_FILE="/var/www/html/google_forms/phpcs_errors.json" # Specify your error file path and format here
|
|
|
|
# Run PHPCS, display errors in the terminal, and store them in the JSON file
|
|
echo "$STAGED_FILES" | xargs -n 1 /home/aissel/.config/composer/vendor/bin/phpcs --standard=/var/www/html/google_forms/phpcs.xml --report=json | tee "$ERROR_FILE"
|
|
|
|
|
|
|
|
|
|
|
|
# Additionally, run PHPCS to show output in terminal in standard format
|
|
echo "$STAGED_FILES" | xargs -n 1 /home/aissel/.config/composer/vendor/bin/phpcs --standard=/var/www/html/google_forms/phpcs.xml
|
|
|
|
# Check if there were any errors reported
|
|
|
|
if grep -q '"errors":' "$ERROR_FILE"; then
|
|
echo "PHPCS errors detected. Please fix them before committing."
|
|
exit 1
|
|
fi
|
|
|
|
# Add the fixed files back to the staging area
|
|
for FILE in $STAGED_FILES; do
|
|
git add "$FILE"
|
|
done
|
|
|
|
echo "Pre-commit checks completed."
|