fangmd / blogsource

6 stars 0 forks source link

使用 husky lint-staged 实现代码提交时自动格式化 #100

Open fangmd opened 1 year ago

fangmd commented 1 year ago

配置 husky 添加 git hooks

# install
pnpm add -D husky

# enable
npx husky install

npm pkg set scripts.prepare="husky install"
npx husky add .husky/pre-commit "pnpm precommit"
# package.json
"precommit": "lint-staged --allow-empty",
pnpm add -D lint-staged
#package.json

  "lint-staged": {
    "src/**/*.{jsx,tsx,ts,js,json,css,less,md}": [
      "prettier --write",
      "git add ."
    ]
  }