代码 commit 前检验处理 yorkie/husky + lint-staged
- 安装
yarn add eslint @commitlint/cli @commitlint/config-conventional lint-staged -S
- 初始化配置
# 第一步初始化 eslint
./node_modules/.bin/eslint --init
# 第三步初始化 commitlint
echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
- 具体配置
package.json
添加lint-staged
配置
{
// ...
"lint-staged": {
"*.js": "eslint --fix"
}
}
- 下载
yarn add husky -S
- 初始化 husky
./node_modules/.bin/husky install
.husky
文件下新增 commit-msg
# fileName: .husky/commit-msg
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit
.husky
文件下新增 pre-commit
# fileName: .husky/pre-commit
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-staged
- husky 不执行。 警告信息:
git config advice.ignoredHook false
chmod +x .husky/pre-commit
# and
chmod +x .husky/commit-msg
- 下载
yarn add yorkie -S
package.json
配置
{
// ...
"gitHooks": {
"commit-msg": "commitlint --edit $1",
"pre-commit": "lint-staged"
}
}