https://github.com/typicode/husky
幫助我們處理git hook時,自動處理我們所寫的規則~!
yarn add husky -D
or
npm install husky --save-dev
yarn add @commitlint/cli @commitlint/config-conventional -D
or
npm install @commitlint/cli @commitlint/config-conventional --save-dev
npx husky install
"scripts": {
//
"prepare": "husky install"
},
可以參考文章~ 關於 git hook
npx husky add .husky/commit-msg 'npx commitlint --edit $1'
#在根目錄新增
commitlint.config.js
#裡面加入
module.exports = {
extends: ['@commitlint/config-conventional'],
};
composer require "squizlabs/php_codesniffer=*" --dev
//composer.json
"scripts": {
//..
// 設定顏色顯示
// 設定規範為 PSR12
"post-install-cmd": [
"phpcs --config-set colors 1",
"phpcs --config-set default_standard PSR12"
],
}
//composer.json
"scripts": {
//..
// phpcs 為檢查
// phpcbf 為修理
// 檢查為 PSR12 (--standard=psr12)
// 顯示進度 (-p)
// 設定檢查範圍 (app/ config/ routes/ tests/)
// 確定是誰向 Git 存儲庫提交了每個錯誤和警告 (--report)
"lint": [
"phpcs --standard=psr12 -p app/ config/ routes/ tests/"
],
"lint:save": [
"phpcbf --standard=psr12 -p app/ config/ routes/ tests/"
],
"lint:report": [
"phpcs --standard=psr12 -p -s --report=gitblame app/ config/ routes/ tests/"
]
}
但是不會 commit 進 git staged 內
yarn add -D lint-staged
npx husky add .husky/pre-commit "npx lint-staged"
設定 phpcbf 修理、PSR12、顯示進度、範圍(app/ config/ routes/ tests/)
// package.json
{
//..
"lint-staged": {
"{app, config, routes, tests}/**/*.php": "composer lint"
}
}