目錄:
  1. 应用场景
    1. 文档
      1. 安装
        1. 使用
          1. 配合husky使用
            1. 问询方式
            2. commit规范

              项目规范化3-commitlint配置和使用

              閱讀時間:全文 481 字,預估用時 3 分鐘
              創作日期:2020-05-05
              文章標籤:
               
              BEGIN

              应用场景

              使用git commit时对Message的规范化, 不符合规范则阻止提交, 让项目更容易管理, 项目迭代也更清晰.

              文档

              项目地址: commitlint Github 🔗

              官网地址: commitlint 🔗

              安装

              1. 安装依赖包: yarn add --dev @commitlint/cli @commitlint/config-conventional
              2. 增加配置文件: echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js

              使用

              配合husky使用

              第一种方式是配合husky增加commit-msg钩子, 执行命令commitlint -E $HUSKY_GIT_PARAMS即可实现commitlint功能

              问询方式

              第二种方式是使用程序问询的方式实现commit msg, 因为使用问询方式, 此时不存在commitlint报错

              安装额外的包prompt-cli: yarn add --dev @commitlint/prompt-cli

              package.json内的scripts中添加"commit": "commit"

              此时在git add .后执行yarn commit即可调用commit-msg问询程序

              commit规范

              规范格式像写邮件, type为提交类型, scope为影响的范围, subject表示主题(一句话概括), body表示主体内容如修改了什么或者增加了什么, footer表示要特别说明的地方, 格式如下:

              type(scope?): subject
              body?
              footer?

              其中scope、body、footer可省略, 在prompt中使用:skip跳过

              其中type的值只能为:

              • feat: Adds a new feature (新功能)
              • fix: Solves a bug (bug修复)
              • docs: Adds or alters documentation (文档变更)
              • style: Improves formatting, white-space (样式变更)
              • refactor: Rewrites code without feature, performance or bug changes (重构, 不包括新功能、性能、bug修复)
              • perf: Improves performance (性能优化)
              • test: Adds or modifies tests (新增或修改单元测试)
              • chore: Other changes that don’t modify src or test files (非src目录下及测试文件的变更)
              • ci: Changes CI configuration files and scripts ( CI配置文件及脚本的变更)
              • build: Affects the build system or external dependencies (会影响到构建系统或外部依赖项)
              • revert: Reverts a previous commit (还原先前的提交)

              type示例:

              1. 项目初始化使用chore: chore: init project
              2. 项目增加想eslint的功能使用chore或feat: chore: setting up eslint
              FINISH

              隨機文章
              人生倒計時
              default