conventional-changelog / commitlint

📓 Lint commit messages
https://commitlint.js.org
MIT License
16.92k stars 911 forks source link

Create a Shareable config when using gitmoji icons #373

Closed romain-gsr closed 6 years ago

romain-gsr commented 6 years ago

Hi and first thanks for your amazing lib !

I'm not sure this issue belongs here but that would be cool to be able to get a Shareable commitlint config for gitmoji tools using icons (instead of using codes, which already exists here).

Reason is that, using icons feels better since they get displayed in, for example, the GIT logs or SourceTree instead of some ugly :code: string.

Of course past the look & feel, in the end what matters the most is to be able to leverage semantic versioning throughout versioning commits messages, so being able to validate messages using this format is mandatory and I felt like this could be a great addition.

Affected packages

Possible Solution

The implementation I bet is quite easy, except for the headerPattern part of the parserOpt. I gave a try this morning but can't find yet why it is parsed correctly and suspects some kind of required string representation of each icon because of encoding.

romain-gsr commented 6 years ago

Found the answer to my question :)

const pattern = {
  iconized: {
    with: /^(🎨|🔥|🐛)(?:\:\((.*?)\))?\s((?:.*(?=\())|.*)(?:\(#(\d*)\))?/,
    without: /^(🎨|🔥|🐛)(?:\((.*?)\))?\s((?:.*(?=\())|.*)(?:\(#(\d*)\))?/
  },
  encoded: /^(:\w*:)(?:\((.*?)\))?\s((?:.*(?=\())|.*)(?:\(#(\d*)\))?/
}
const iconized = {
  with: '🎨:(core) Art\n\nThis is art !\n\nBREAKING CHANGE with former style (resolve #13)',
  without: '🎨(core) Art\n\nThis is art !\n\nBREAKING CHANGE with former style (resolve #13)',
}
const encoded = ':art:(core) Art\n\nThis is art !\n\nBREAKING CHANGE with former style (resolve #13)'

const match = (sentence, pattern) => sentence.match(pattern)
const log = (sentence, pattern) => match(sentence, pattern)
? `it matches`
: `it doesn't match`

console.log(`using icon with intermediate colon before scope:`, log(iconized.with, pattern.iconized.with))
console.log(`using icon without intermediate colon before scope:`, log(iconized.without, pattern.iconized.without))
console.log(`using code:`, log(encoded, pattern.encoded))
romain-gsr commented 6 years ago

Actually, using gitmoji-cli the best pattern would be:

const pattern = /^((🎨|🔥|🐛))\:(?:\((.*?)\))?\s((?:.*(?=\())|.*)(?:\(#(\d*)\))?/

But I'm still looking why I get a ✖ message may not be empty [subject-empty] because of how gitmoji-cli format the commit message (extending commitlint-config-gitmoji).

romain-gsr commented 6 years ago

So I finally understood, summarized :

marionebl commented 6 years ago

You can pass arbitrary options to conventional-commits-parser which is used to get structured data out of your input.

I suggest you land your wanted changes on either gitmoji-cli and cz-gitmoji-changelog or commitlint-config-gitmoji.