Skip to content

commlint Always wrong? #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xieyezi opened this issue Dec 22, 2019 · 6 comments
Closed

commlint Always wrong? #39

xieyezi opened this issue Dec 22, 2019 · 6 comments

Comments

@xieyezi
Copy link

xieyezi commented Dec 22, 2019

Hi,@whizark, I appear some isses again.

What happened

I npm install those:

   "@commitlint/cli": "^8.2.0",
    "commitizen": "^4.0.3",
    "commitlint-config-cz": "^0.12.1",
    "cz-customizable": "^6.2.0",
    "husky": "^3.1.0",

this is my .cz.config.js:

module.exports = {
  types: [
    { value: 'feat✨', name: '特性: 一个新的特性' },
    { value: 'fix🐞', name: '修复: 修复一个Bug' },
    { value: 'docs📚', name: '文档: 变更的只有文档' },
    { value: 'style💅', name: '格式: 空格, 分号等格式修复' },
    { value: 'refactor🛠', name: '重构: 代码重构,注意和特性、修复区分开' },
    { value: 'perf🐎', name: '性能: 提升性能' },
    { value: 'test🏁', name: '测试: 添加一个测试' },
    { value: 'revert⏪', name: '回滚: 代码回退' },
    { value: 'chore🗯', name: '工具:开发工具变动(构建、脚手架工具等)' }
  ],
  messages: {
    type: '选择一种你的提交类型:',
    customScope: '请输入修改范围(可选):',
    subject: '短说明:',
    body: '长说明,使用"|"换行(可选):',
    footer: '关联关闭的issue,例如:#31, #34(可选):',
    confirmCommit: '确定提交说明?'
  },
  allowCustomScopes: true,
  allowBreakingChanges: ['特性', '修复'],
  subjectLimit: 100
}

this is my commitlint.config.js:

module.exports = {
    extends: [
        'cz'
    ],
    rules: {
        'type-empty': [2, 'never'],
        'subject-empty': [2, 'never']
    }
}

and this is my project.json settings:

...
"config": {
    "commitizen": {
      "path": "node_modules/cz-customizable"
    }
  },
  "cz-customizable": {
    "config": ".cz-config.js"
  },
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  }

after I finish those step, I use npm run commit to generate commit message, but the commlint check always fails !😫 Just like this:

屏幕快照 2019-12-22 16 32 55

In fact, I have selected the type and input the subject. you can see:

? 选择一种你的提交类型: 修复: 修复一个Bug   // this is my type
? 短说明: 代码提交bug   // this is my subject

But the commlint check always fails ! I don't know why, hope got your help !!

My Project

https://github.com/xieyezi/Learn-notes

@whizark
Copy link
Owner

whizark commented Dec 23, 2019

@xieyezi Hi, it looks the error isn't caused by commitlint-config-cz but also commitlint. I confirmed Emoji (:beetle: etc.) in your commit message causes it. I think your case is related to "cant use commit with emoji · Issue #610 · conventional-changelog/commitlint".

commitlint internally uses conventional-commits-parser and it has "headerPattern" option, which allows you to customize header pattern (type, scope, subject).
You may add it in your commitlint.config.js but it might not work according to "How to use parser headerPattern · Issue #607 · conventional-changelog/commitlint".

You can watch, contribute the issues above, or just removing Emoji in your type should solve the issue.

@xieyezi
Copy link
Author

xieyezi commented Dec 23, 2019

@whizark Hi ,thanks your so detail explanation, After I detele emoji, it work normally. But I wanna use it with emoji , I find all the doc and isses with commlint, I find maybe I need turn emoji into character types and setting the headerPattern! I'll go find best way to resolve this problem ,and I will close this question at that time. thanks again!

@whizark
Copy link
Owner

whizark commented Dec 23, 2019

@xieyezi

After I detele emoji, it work normally.

Nice to hear that!

I find maybe I need turn emoji into character types and setting the headerPattern

Yes, headerPattern is a key, but it seems not to work well 😢
I close this issue because it is commitlint's matter rather than commitlint-config-cz (this package). I hope you can find the best way 👍

@tomavic
Copy link

tomavic commented Jun 18, 2022

@xieyezi Did you found a way on how to use emojis with commitlint?

@elton11220
Copy link

@xieyezi Did you found a way on how to use emojis with commitlint?

I am enabled to use emojis by adding the following config to commitlint.config.js

module.exports = {
  extends: ["cz"],
  rules: {
    "subject-empty": [2, "never"],
    "type-empty": [2, "never"],
  },
  parserPreset: {
    parserOpts: {
      headerPattern:
        /^(?<type>.*\s\w*)(?:\((?<scope>.*)\))?!?:\s(?<subject>(?:(?!#).)*(?:(?!\s).))$/,
      headerCorrespondence: ["type", "scope", "subject"],
    },
  },
};

This RegExp is borrowed from this repository: https://github.com/ccnnde/commitlint-config-git-commit-emoji

@wakaka378
Copy link

You can try this

// .cz-config.js
types: [
    {
      value: ':rocket: release',
      name: '🚀  release:  发布版本/发布标签',
    },
    {
      value: ':construction: WIP',
      name: '💪  WIP:      正在进行的工作',
    },
    {
      value: ':sparkles: feat',
      name: '✨  feat:     新的特性',
    },
    {
      value: ':bug: fix',
      name: '🐛  fix:      修复Bug',
    },
    {
      value: ':wrench: CI',
      name: '🔧  CI:       目录结构变更(CI, Building, Tool...)',
    },

    {
      value: ':pencil: docs',
      name: '📝  docs:     仅文档更改',
    },
    {
      value: ':twisted_rightwards_arrows: merge',
      name: '🔀  merge:    合并分支',
    },
    {
      value: ':rewind: revert',
      name: '⏪  revert:   版本回滚',
    },
    {
      value: ':white_check_mark: test',
      name: '✅  test:     添加缺失的测试或更正现有测试',
    },
    {
      value: ':chart_with_upwards_trend: perf',
      name: '📈  perf:     提高性能的代码更改',
    },
    {
      value: ':thought_balloon: chore',
      name: '🗯   chore:    不修改src或测试文件的更改。例如更新构建任务、包管理器',
    },
    {
      value: ':lipstick: ui',
      name: '💄  UI:       更新UI和样式文件。',
    },
    {
      value: ':art: style',
      name: '🎨  style:    不影响代码含义的更改(空白、格式、缺少分号等)',
    },
    {
      value: ':package: dep_up',
      name: '📦  dep_up:   更新已编译的文件或包。',
    },

    {
      value: ':hammer: refactor',
      name: '🔨  refactor: 既不修复错误也不添加功能的代码更改',
    },
    {
      value: ':truck: mv',
      name: '🚚  mv:       移动或重命名文件。',
    },
  ],

Use the identifier to replace emoji

github emoji

But the CHANGELOG generated in this way has a big problem

Because he destroyed the specification

I can't solve it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants