Zhengqbbb / cz-git

cz-git | czg 🛠️ DX first and more engineered, lightweight, customizable, standard output format Commitizen adapter and CLI
https://cz-git.qbb.sh
MIT License
1.05k stars 39 forks source link

[Help] emojiAlign 设为 left 后无法提交信息。 #151

Closed SuiKaSan closed 8 months ago

SuiKaSan commented 8 months ago

✅ Checklist

📄 System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 AMD Ryzen 7 7735HS with Radeon Graphics        
    Memory: 6.06 GB / 28.75 GB
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    commitizen: ^4.3.0 => 4.3.0
    cz-git: ^1.8.0 => 1.8.0

🔎 Description

我已看过bug单 #114 ,按照其中提供的例子进行修改,依然无法通过校验。

请问有人遇到这种情况吗? 这是我的配置文件


/**
 * @type {import('cz-git').UserConfig}
 *  */
module.exports = {
    ignores: [(commit) => commit.includes('init')],
    extends: ['@commitlint/config-conventional'],
    rules: {
        'body-leading-blank': [2, 'always'],
        'footer-leading-blank': [1, 'always'],
        'header-max-length': [2, 'always', 50],
        'subject-empty': [2, 'never'],
        'type-empty': [2, 'never'],
        'subject-case': [0],
        'type-enum': [2, 'always', ['✨ feat', '🐞 fix', '📝 docs', '💄 style', '♻️ refactor', '⚡️ perf', '✅ test', '📦️ build', '🎡 ci', '🔨 revert', '⏪️ chore']],
    },
    prompt: {
        alias: {
            f: 'docs: fix typos',
            r: 'docs: update README',
            s: 'style: update code format',
            b: 'build: bump dependencies',
            c: 'chore: update config',
        },
        customScopesAlign: 'top',
        defaultScope: ['custom'],
        scopes: ['scene', 'room', 'docker', 'setting', 'pilot feature', 'matter', 'cast', 'security', 'etc'],
        allowCustomScopes: true,
        allowEmptyScopes: true,
        allowEmptyIssuePrefixs: true,
        allowCustomIssuePrefixs: true,
        messages: {
            type: '选择你要提交的类型 :',
            scope: '选择一个提交范围(可选):',
            customScope: '请输入自定义的提交范围 :',
            subject: '填写简短精炼的变更描述 :\n',
            body: '填写更加详细的变更描述(可选)。使用 "|" 换行 :\n',
            confirmCommit: '是否提交或修改commit ?',
        },
        types: [
            { value: 'feat', name: 'feat:      ✨ 新增功能 | A new feature', emoji: '✨' },
            { value: 'fix', name: 'fix:       🐞 修复缺陷 | A bug fix', emoji: '🐞' },
            {
                value: 'docs',
                name: 'docs:      📝 文档更新 | Documentation only changes',
                emoji: '📝',
            },
            {
                value: 'style',
                name: 'style:     💄 代码格式 | Changes that do not affect the meaning of the code',
                emoji: '💄',
            },
            {
                value: 'refactor',
                name: 'refactor:  ♻️  代码重构 | A code change that neither fixes a bug nor adds a feature',
                emoji: '♻️',
            },
            {
                value: 'perf',
                name: 'perf:      ⚡️ 性能提升 | A code change that improves performance',
                emoji: '⚡️',
            },
            {
                value: 'test',
                name: 'test:      ✅ 测试相关 | Adding missing tests or correcting existing tests',
                emoji: '✅',
            },
            {
                value: 'build',
                name: 'build:     📦️ 构建相关 | Changes that affect the build system or external dependencies',
                emoji: '📦️',
            },
            {
                value: 'ci',
                name: 'ci:        🎡 持续集成 | Changes to our CI configuration files and scripts',
                emoji: '🎡',
            },
            { value: 'revert', name: 'revert:    🔨 回退代码 | Revert to a commit', emoji: '🔨' },
            {
                value: 'chore',
                name: 'chore:     ⏪️ 其他修改 | Other changes that do not modify src or test files',
                emoji: '⏪️',
            },
        ],
        useEmoji: true,
        emojiAlign: 'left',
        themeColorCode: '',
        upperCaseSubject: false,
        skipQuestions: ['breaking', 'footer', 'footerPrefix'],
        breaklineNumber: 100,
        breaklineChar: '|',
        confirmColorize: true,
        minSubjectLength: 0,
        scopeOverrides: undefined,
        defaultBody: '',
        defaultIssues: '',
        defaultSubject: '',
    },
};

校验后报错依旧: image

🔗 Reproduction link / repo:

No response

Zhengqbbb commented 8 months ago
  1. 无法通过校验,是校验工具的配置有问题,与我辅助 commit 工具有什么关系吗?
  2. 你使用 git commit -m '⚡ pref: test' 一样提交不了
  3. 后面有问题可以提帮助帖子,不要提 BUG issue
Zhengqbbb commented 8 months ago

/**
 * @type {import('cz-git').UserConfig}
 *  */
module.exports = {
  ignores: [(commit) => commit.includes('init')],
  extends: ['@commitlint/config-conventional'],
  rules: {
      'body-leading-blank': [2, 'always'],
      'footer-leading-blank': [1, 'always'],
      'header-max-length': [2, 'always', 50],
      'subject-empty': [2, 'always'],
      'type-empty': [2, 'always'],
      'subject-case': [0],
      'type-enum': [2, 'always', ['✨ feat', '🐞 fix', '📝 docs', '💄 style', '♻️ refactor', '⚡️ perf', '✅ test', '📦️ build', '🎡 ci', '🔨 revert', '⏪️ chore']],
  },
  prompt: {
      alias: {
          f: 'docs: fix typos',
          r: 'docs: update README',
          s: 'style: update code format',
          b: 'build: bump dependencies',
          c: 'chore: update config',
      },
      customScopesAlign: 'top',
      defaultScope: ['custom'],
      scopes: ['scene', 'room', 'docker', 'setting', 'pilot feature', 'matter', 'cast', 'security', 'etc'],
      allowCustomScopes: true,
      allowEmptyScopes: true,
      allowEmptyIssuePrefixs: true,
      allowCustomIssuePrefixs: true,
      messages: {
          type: '选择你要提交的类型 :',
          scope: '选择一个提交范围(可选):',
          customScope: '请输入自定义的提交范围 :',
          subject: '填写简短精炼的变更描述 :\n',
          body: '填写更加详细的变更描述(可选)。使用 "|" 换行 :\n',
          confirmCommit: '是否提交或修改commit ?',
      },
      types: [
          { value: 'feat', name: 'feat:      ✨ 新增功能 | A new feature', emoji: '✨' },
          { value: 'fix', name: 'fix:       🐞 修复缺陷 | A bug fix', emoji: '🐞' },
          {
              value: 'docs',
              name: 'docs:      📝 文档更新 | Documentation only changes',
              emoji: '📝',
          },
          {
              value: 'style',
              name: 'style:     💄 代码格式 | Changes that do not affect the meaning of the code',
              emoji: '💄',
          },
          {
              value: 'refactor',
              name: 'refactor:  ♻️  代码重构 | A code change that neither fixes a bug nor adds a feature',
              emoji: '♻️',
          },
          {
              value: 'perf',
              name: 'perf:      ⚡️ 性能提升 | A code change that improves performance',
              emoji: '⚡️',
          },
          {
              value: 'test',
              name: 'test:      ✅ 测试相关 | Adding missing tests or correcting existing tests',
              emoji: '✅',
          },
          {
              value: 'build',
              name: 'build:     📦️ 构建相关 | Changes that affect the build system or external dependencies',
              emoji: '📦️',
          },
          {
              value: 'ci',
              name: 'ci:        🎡 持续集成 | Changes to our CI configuration files and scripts',
              emoji: '🎡',
          },
          { value: 'revert', name: 'revert:    🔨 回退代码 | Revert to a commit', emoji: '🔨' },
          {
              value: 'chore',
              name: 'chore:     ⏪️ 其他修改 | Other changes that do not modify src or test files',
              emoji: '⏪️',
          },
      ],
      useEmoji: true,
      emojiAlign: 'left',
      themeColorCode: '',
      upperCaseSubject: false,
      skipQuestions: ['breaking', 'footer', 'footerPrefix'],
      breaklineNumber: 100,
      breaklineChar: '|',
      confirmColorize: true,
      minSubjectLength: 0,
      scopeOverrides: undefined,
      defaultBody: '',
      defaultIssues: '',
      defaultSubject: '',
  },
};
WakerCN commented 7 months ago

https://github.com/Zhengqbbb/cz-git/issues/151#issuecomment-1865393397

可是按照这个设置,将这两条规则设置为always,不符合要求的commit-msg也会通过校验,@Zhengqbbb

image

SuiKaSan commented 7 months ago

是的,所以我后面还是改为将emoji放在中间了,毕竟也不是特别大的问题。

Zhengqbbb commented 7 months ago

是因为 Emoji 放在第一位并不是传统的约定式提交协议规定,所以 cz-git 默认是放在描述头部避免与协议冲突,哪怕是其他 commitlint 校验工具也不支持Emoji字符放在第一位。

所以关键是找到非传统的 commitlint 校验规则:例如 https://github.com/ccnnde/commitlint-config-git-commit-emoji

  1. 删除例如 extends 中的 @commitlint/config-conventional 替换为 git-commit-emoji
  2. 替换包
    npm remove @commitlint/config-conventional
    npm install -D commitlint-config-git-commit-emoji

当然也可以不引入配置依赖,手动参照这份配置文件进行配置