ソースを参照

Add linting as suggested by @jrbasso

Jad Bitar 11 年 前
コミット
79771590f1
1 ファイル変更15 行追加2 行削除
  1. 15 2
      contrib/pre-commit

+ 15 - 2
contrib/pre-commit

@@ -1,5 +1,6 @@
 #!/bin/sh
 FILES=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
+PROJECT=`php -r "echo dirname(dirname(realpath('$0')));"`
 
 # Determine if a file list is passed
 if [ "$#" -eq 1 ]
@@ -12,7 +13,19 @@ then
 fi
 SFILES=${SFILES:-$FILES}
 
-if [ "$FILES" != "" ]
+echo "Checking PHP Lint..."
+for FILE in $SFILES
+do
+    php -l -d display_errors=0 $PROJECT/$FILE
+    if [ $? != 0 ]
+    then
+        echo "Fix the error before commit."
+        exit 1
+    fi
+    FILES="$FILES $PROJECT/$FILE"
+done
+
+if [ "$SFILES" != "" ]
 then
     echo "Running PHPCS"
     ./vendor/bin/phpcs --standard=vendor/cakephp/cakephp-codesniffer/CakePHP $SFILES
@@ -22,4 +35,4 @@ then
         exit 1
     fi
 fi
-exit $?
+exit $?