1. 統一使用AlibabaCode代碼規範校驗
以idea開發工具爲準
在Prefercences -> Plugins -> marketPlace 路徑下
安裝AlibabaCoding Guidlines 。
在每次提交代碼前,務必使用該工具進行代碼檢測。
安裝完畢後 右鍵項目 => 代碼規範檢測 在下方可看到不符合規範的代碼
2. git提交規範
下載:git clone https://github.com/blog-plat-dev/convention-git.git
安裝方式:
將commit-msg 覆蓋掉項目中 ./git/hooks/路徑下的commit-msg.sample
主要的Type操作符:
- Init
項目初始化
- Feat
增加新功能
- Remove
- Delete
- Move
- New
- Add
- Patch
補丁
- Fix
修復bug
- Test
測試
案例 提交方式:[Add] message
Shell代碼:
# !/bin/bash
filename=$1
# read commit message in file
content=$(cat $1)
COMMIT_MESSAGE_CONVENTION_REGEX='^(\[(Init|Update|Remove|Move|Delete|New|Add|Patch|Fix)\]) .+$';
COMMIT_MESSAGE_OPERATION_SYMBOL_REGEX='^\[.+\]'
COMMIT_MESSAGE_SPACE_REGEX='^\[.+\] '
COMMIT_MESSAGE_MESSAGE_REGEX='^\[.+\] .+$'
COMMIT_MESSAGE_OPERATION_REGEX='^\[.+\] .+'
print_red_msg(){
echo -e "\033[31m${1}\033[0m"
}
print_error_msg(){
print_red_msg "[CommitMessageError]$1"
print_red_msg "\nExample: [Init] this is a commit message"
exit 1
}
if [[ ! $content =~ $COMMIT_MESSAGE_CONVENTION_REGEX ]]
then
# check []
if [[ ! $content =~ $COMMIT_MESSAGE_OPERATION_SYMBOL_REGEX ]]
then
print_error_msg "Missing '['"
fi
# check space
if [[ ! $content =~ $COMMIT_MESSAGE_SPACE_REGEX ]]
then
print_error_msg "Missing blank space"
fi
if [[ ! $content =~ $COMMIT_MESSAGE_MESSAGE_REGEX ]]
then
print_error_msg "Missing message of commit"
else
print_error_msg "Please make sure your operation is correct\nOperations: Init|Update|Remove|Delete|New|Add|Patch|Fix"
fi
fi