Precommit hook - mattzhao92/Planet-Blitz GitHub Wiki

Run sudo npm install jshint -g

Navigate to the top-level directory of the repository. Do:

cd .git/hooks

Create a file pre-commit with the following contents:

#!/bin/sh
#
# Run JSHint validation before commit.

files=$(git diff --cached --name-only --diff-filter=ACMR -- *.js **/*.js)
pass=true


if [ "$files" != "" ]; then
    for file in ${files}; do
        result=$(jshint ${file})

        if [ "$result" != "" ]; then
            echo $result
            pass=false
        fi
    done
fi


if $pass; then
    exit 0
else
    echo ""
    echo "COMMIT FAILED:"
    echo "Some JavaScript files are invalid. Please fix errors and try committing again."
    exit 1
fi

Then run: chmod 755 pre-commit

What this does: enforces good code style and points out some tricky errors (ex. the subtraction after the "return" of the player kill sort function).