由于缺少成员文档,gJSLint会发现错误。我们更新了使用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版
答案 0 :(得分:1)
这个问题与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
eval "gjslint --strict --disable=5,6,110,220 ${file}"
if [ $? -eq 0 ]; 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