代码规范&提交规范

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章