嗨,大家好我有一個git倉庫3個文件夾(個人js項目)。我如何添加linting到預鉤鉤子
這裏是我的pre-commit
鉤
#!/bin/bash
echo -e "\033[1;92m Linting Staged Files . . . "
files=$(git diff --diff-filter=d --cached --name-only | grep -E '\.(js|jsx)$')
path=(${files[0]//// })
if [[ $files = "" ]] ; then
echo -e "\033[1;31m You have no staged file, exiting . . "
exit 1
fi
for file in $files
do
git show ":$file" | $("./$path/node_modules/.bin/eslint --stdin --stdin-filename $file")
if [ $? -ne 0 ]; then
echo -e "\033[1;31m ESLint failed on staged file '$file'. \n Code will not be committed, Please fix your code and try again."
exit 1
fi
done
BRANCH=`git rev-parse --abbrev-ref HEAD`
if [[ "$BRANCH" == "master" || "$BRANCH" == "develop" ]]; then
echo "\033[1;31m commiting to $BRANCH is illegal."
echo "\033[1;31m If you really know what you're doing, then add the argument '-n' to skip this git hook."
exit 1
fi
exit 0
但它一直在這一行git show ":$file" | $("./$path/node_modules/.bin/eslint --stdin --stdin-filename $file")
一個錯誤
.git/hooks/pre-commit: line 17: ./node_modules/.bin/eslint --stdin --stdin-filename sfa/src/SFAApp.js: No such file or directory
我不知道我做錯了什麼故障,請幫幫我。
就像我說的混帳回購協議具有不成立一個實際的項目,但與他們不同的項目其他文件夾,因此我必須獲取修改文件的文件夾名稱並執行** that **文件夾的eslint,以及該文件夾的配置。 –
啊哈。那麼,如果'a/dir1/file1.js' *和*'b/dir2/file2.js'中有更改或新文件,那麼這不起作用。你需要爲每個文件選擇正確的路徑*(或者可能禁止影響多個子項目的提交)。 – torek
我可能需要獲取每個文件的文件夾路徑,而不是僅獲取第一個文件。非常感謝。 –