Run jshint when git commit

#!/bin/sh

#

# Run JSHint validation before commit.

files=$(git diff --cached --name-only --diff-filter=ACMR -- *.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

猜你喜欢

转载自qlqllu.iteye.com/blog/2072289