conventional-changelog / commitlint

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

Type failed with Gitmoji commit #273

Closed arvinxx closed 6 years ago

arvinxx commented 6 years ago

Here is the Gitmoji Introduction. https://gitmoji.carloscuesta.me/ I'm using gitmoji style in my commit. And I try to get commitlint into my workflow to avoid mistake. According to @commitlint/config-conventional,I change the type-enum to suit the emoji name.Here is the code.

  rules: {
    'type-enum': [
      2,
      'always',
      [
        ':art:',
        ':zap:',
        ':fire:',
        ':bug:',
        ':ambulance:',
        ':sparkles:',
        ':memo:',
        ':rocket:',
        ':lipstick:',
        ':tada:',
          ...
      ],

Expected Behavior

Wen I try some commit infomation, I think there should not be any problem.

$ echo ":art:: fodo ddd" | .\node_modules\.bin\commitlint
⧗   input: :art: fodo ddd
✔   found 0 problems, 0 warnings

Current Behavior

However , there it is.

$ echo ":art: fodo ddd" | .\node_modules\.bin\commitlint
⧗   input: :art: fodo ddd
✖   message may not be empty [subject-empty]
✖   type may not be empty [type-empty]
✖   found 2 problems, 0 warnings

It seems that commitlint recongizes the first : to be the type. So the type becomes empty. But I'm confusing why subject is also empty.

Affected packages

Possible Solution

Maybe commitlint should add a recongaztion for gitmoji style?

Steps to Reproduce (for bugs)

1. 2. 3. 4.

commitlint.config.js ```js module.exports = { rules: { 'type-enum': [ 2, 'always', [ // I did no other changes expect this arrays ':art:', ':zap:', ':fire:', ':bug:', ':ambulance:', ':sparkles:', ':memo:', ':rocket:', ':lipstick:', ':tada:', ':white_check_mark:', ':lock:', ':apple:', ':penguin:', ':checkered_flag:', ':robot:', ':green_apple:', ':bookmark:', ':rotating_light:', ':construction:', ':green_heart:', ':arrow_down:', ':arrow_up:', ':construction_worker:', ':chart_with_upwards_trend:', ':hammer:', ':heavy_minus_sign:', ':whale:', ':heavy_plus_sign:', ':wrench:', ':globe_with_meridians:', ':pencil2:', ':hankey:', ':rewind:', ':twisted_rightwards_arrows:', ':package:', ':alien:', ':truck:', ':page_facing_up:', ':boom:', ':bento:', ':ok_hand:', ':wheelchair:', ':bulb:', ':beers:', ':speech_balloon:', ':card_file_box:', ':loud_sound:', ':mute:', ], ], 'body-leading-blank': [1, 'always'], 'footer-leading-blank': [1, 'always'], 'header-max-length': [2, 'always', 50], 'scope-case': [2, 'always', 'lower-case'], 'subject-case': [ 2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case'], ], 'subject-empty': [2, 'never'], 'subject-full-stop': [2, 'never', '.'], 'type-case': [2, 'always', 'lower-case'], 'type-empty': [2, 'never'], }, }; ```

Context

Your Environment

Executable Version
commitlint --version 6.1
git --version version 2.14.2.windows.3
node --version v8.7.0
marionebl commented 6 years ago

conventional-commits-parser does not pick up types with : in them, so both type and subject are empty in the parsed message: https://runkit.com/marionebl/5a85e582beab1d0012df9351

conventional-commits-parser is very configurable, so we should be able to come up with a setting that allows for gitmoji commits.


Edit: A parser config that yields expected results: https://runkit.com/marionebl/5a85e9ecc2ec590012fc7bc6


Edit: In terms of commitlint config this means:

module.exports = {
  parserPreset: {
    parserOpts: {
      headerPattern: /^(:(?:\w+):) (.*)$/,
      headerCorrespondence: ['type', 'subject']
    }
  },
  rules: {
    'type-empty': [2, 'never']
    'type-enum': [2, 'always', [':art:']] // shortened for readability
  }
};
λ echo "foo" | commitlint
⧗   input: foo
✖   type may not be empty [type-empty]
✖   found 1 problems, 0 warnings

λ echo ":foo: bar" | commitlint
⧗   input: :foo: bar
✖   type must be one of [:art:] [type-enum]
✖   found 1 problems, 0 warnings

λ echo ":art: bar" | commitlint
⧗   input: :art: bar
✔   found 0 problems, 0 warnings
ahmadawais commented 5 years ago

@marionebl

I have the same issue but in my case I am trying to build a configuration for my Emoji-log spec. And commit linter doesn't pick up the emoji.

/**
 * Commit Lint
 *
 * Rules are made up by a name and a configuration array.
 * The configuration array contains:
 * 1. Level:      | [0..2] | 0 = disables | 1 = considered a warning | 2 an error for the rule.
 * 2. Applicable: | always/never | never inverts the rule.
 * 3. Value:      | value to use for this rule.
 *
 * @link https://github.com/marionebl/commitlint/blob/master/docs/reference-rules.md
 */

module.exports = {
    rules: {
        'body-leading-blank': [1, 'always'],
        'footer-leading-blank': [1, 'always'],
        'header-max-length': [2, 'always', 72],
        'scope-case': [2, 'always', 'lower-case'], // ?
        'subject-case': [2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case']], // ?
        'subject-empty': [2, 'never'],
        'subject-full-stop': [2, 'never', '.'],
        'type-empty': [2, 'never'],
        'type-case': [2, 'always', 'upper-case'],
        'type-enum': [
            2,
            'always',
            ['📦 NEW', '👌 IMPROVE', '🐛 FIX', '🚀 RELEASE', '🦄 RELEASE', '📖 DOC', '✅ TEST']
        ]
    }
};

When I try the git commit as per Emoji log — I get error

echo "📦 NEW: A git commit msg here" | $(npm bin)/commitlint
⧗   input:
📦 NEW: A git commit msg here

✖   message may not be empty [subject-empty]
✖   type may not be empty [type-empty]
✖   found 2 problems, 0 warnings

image

Help, looking forward, peace! ✌️

ahmadawais commented 5 years ago

So I figured it out. Not perfect as it doesn't judge the emoji but it'll do for now.

headerPattern: /^(.*\w*): (.*)$/,

Kindly, consider using this in the parser https://github.com/egoist/emoji-regex-latest