Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 89 lines (79 sloc) 2.46 KB
#!/bin/bash
# Check PHP file $1 syntax and exit with exit code 1 if there are any errors
test_php_file_syntax() {
if [[ "$1" =~ .(php|inc)$ ]] && ! php -l "$1" > /dev/null;
then
echo
echo -e "\e[31mPHP syntax checker failed\e[0m"
echo
echo -e "\tFile: \e[34m$1\e[0m"
echo
echo -e "\tReason:"
php -l "$1" | sed "s/^/\t\t/"
echo
exit 1
fi
}
# Check for newly introduced PSR issues
test_php_psr() {
if [[ "$1" =~ .(php|inc)$ ]]
then
git show HEAD:"$1" > /tmp/.test_file.php
errors_before=$(phpcs /tmp/.test_file.php | egrep ' ERROR| WARNING' | wc -l)
errors_after=$(phpcs "$1" | egrep ' ERROR| WARNING' | wc -l)
if [[ $errors_after -gt $errors_before ]]
then
echo
echo -e "\e[31mPSR checker failed\e[0m"
echo
echo -e "\tFile: \e[34m$1\e[0m"
echo -e "\tReason: you have introduced $(($errors_after-$errors_before)) new PSR problems"
echo
fi
fi
}
# Check file $1 for words $2
test_words_existance() {
if git diff --cached -U0 "$1" | grep -P '^[+-]' | grep -Ev '^(--- a/|\+\+\+ b/|-)' | grep -q "$2"
then
echo
echo -e "\e[31mWords checker failed\e[0m"
echo
echo -e "\tFile: \e[34m$1\e[0m"
echo -e "\tReason: has word \e[96m$2\e[0m in newly written code."
echo
git diff --cached -U0 "$1" | grep -P '^[+-]' | grep -Ev '^(--- a/|\+\+\+ b/|-)' | grep "$2" | sed "s/^/\t\t/" | cut -c 1-100
echo
if [ ! -z "$3" ]
then
exit 1
fi
fi
}
while read st file
do
# skip deleted files
if [ "$st" == 'D' ]
then
continue
fi
# Generic
test_words_existance "$file" TODO
test_words_existance "$file" FIXME
test_words_existance "$file" XXX
# PHP
test_php_file_syntax "$file"
test_php_psr "$file"
test_words_existance "$file" var_dump fatal
test_words_existance "$file" print_r fatal
test_words_existance "$file" error_reporting fatal
test_words_existance "$file" debug_backtrace fatal
# JavaScript
test_words_existance "$file" console.log fatal
test_words_existance "$file" debugger fatal
# Python
test_words_existance "$file" set_trace fatal
test_words_existance "$file" print
test_words_existance "$file" pprint fatal
test_words_existance "$file" __dict__ fatal
done < <(git diff --cached --name-status)
You can’t perform that action at this time.