# Commitlint ## Install 這部分看[官方範例](https://github.com/conventional-changelog/commitlint#getting-started)就可以了 ## 觸發較驗 綁定在husky提供的hook,就能夠在每次git commit trigger後觸發較驗,如IDE的提交按鈕或是git cz交互後立即較驗。 - package.json ```json= { "husky": { "hooks": { "commit-msg": "commitlint --edit $1" } } } ``` ## 較驗規則 這邊使用的基本規則是用@commitlint/config-conventional來進行基本格式較驗。 > type(scope): description > fix(core): remove console.log - commitlint.config.js ```javascript= module.exports = { extends: ['@commitlint/config-conventional'], }; ``` 在monorepo的架構上會需要規範scope的內容,這時候可以參考以下設定。 - commitlint.config.js ```javascript= module.exports = { rules: { 'scope-enum': [ 2, 'always', [ 'workspace', 'auth', 'cli', 'components', 'core', 'layout', ], ], }, } ```