由于缺少成员文档,gJSLint 会吐出错误。我们更新了我们的 pre-commit 钩子,任务是 linting JavaScript。编辑包括 gJSLint 规则 220(忽略缺少的成员文档)。但是,在执行提交时,GIT 仍然抱怨 JavaScript 无效。单独运行 gJSLint 不会产生错误。
gjslint --strict --disable=5,6,110,220 app/pits/modules/api.js
我们已经删除了暂存文件,然后将它们添加回暂存中,但没有成功。
GIT 是否缓存预提交挂钩?
预提交钩子
#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$") if [ "$files" = "" ]; then
exit 0 fi
pass=true
echo "\nValidating JavaScript:\n"
for file in ${files}; do
result=$(gjslint --strict --disable=5,6,110,220 ${file} | grep "${file} is OK")
if [ "$result" != "" ]; then
echo "\t\033[32mJSLint Passed: ${file}\033[0m"
else
echo "\t\033[31mJSLint Failed: ${file}\033[0m"
pass=false
fi done
echo "\nJavaScript validation complete\n"
if ! $pass; then
echo "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass JSLint but do not. Please fix the JSLint errors and try again.\n try: gjslint --strict --disable=5,6,110,220 file.js\n"
exit 1 else
echo "\033[42mCOMMIT SUCCEEDED\033[0m\n" fi
git commit -m"...." 的结果
验证 JavaScript:
JSLint 失败:app/pits/modules/api.js
JSLint 失败:app/pits/modules/State.js
JSLint 失败:app/pits/modules/table.js
JavaScript 验证完成
COMMIT FAILED:您的提交包含应该通过 JSLint 但
do not. Please fix the JSLint errors and try again. try: gjslint --strict --disable=5,6,110,220 file.js
环境
git 版本 1.8.1.2
gjslint 版本 2.3.13
lubuntu 版本 13.04