我不相信这是完成任务的最佳方式。基本上,代码在 repo 中生成每个 JavaScript 文件的文件,然后分别调用 JSHint。奖励它实际上使用项目的 .jshintrc 文件(如果存在)。也在要点上
任何建议,指针,替代品???
#!/bin/bash
# --- Command line
refname="$1"
oldrev="$2"
newrev="$3"
branch=${refname#refs/heads/}
# Make a temp directory for writing the .jshintrc file
TMP_DIR=`mktemp -d`
EXIT_CODE=0
# If commit was on the master branch
if [ "$branch" == "master" ]
then
# See if the git repo has a .jshintrc file
JSHINTRC=`git ls-tree --full-tree --name-only -r HEAD -- | egrep .jshintrc`
JSHINT="jshint"
if [ -n "$JSHINTRC" ]
then
# Create a path to a temp .jshintrc file
JSHINTRC_FILE="$TMP_DIR/`basename \"$JSHINTRC\"`"
# Write the repo file to the temp location
git cat-file blob HEAD:$JSHINTRC > $JSHINTRC_FILE
# Update the JSHint command to use the configuration file
JSHINT="$JSHINT --config=$JSHINTRC_TMP_DIR/$JSHINTRC"
fi
# Check all of the .js files
for FILE in `git ls-tree --full-tree --name-only -r ${newrev} -- | egrep *.js`; do
FILE_PATH=`dirname ${FILE}`
FULL_PATH=${TMP_DIR}/${FILE_PATH}
mkdir -p ${FULL_PATH}
git cat-file blob ${newrev}:${FILE} > "$TMP_DIR/$FILE"
${JSHINT} ${TMP_DIR}/${FILE} >&2
# Exit status of last command
EXIT_CODE=$((${EXIT_CODE} + $?))
if [[ $EXIT_CODE -ne 0 ]]
then
rm -rf ${TMP_DIR}
exit $EXIT_CODE
fi
done
rm -rf ${TMP_DIR}
fi
# Not updating master
exit 0