commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

Custom error message if commit format is wrong.

Open Manubi opened this issue 3 years ago • 10 comments

The idea is pretty simple. If someone commits the first time to a new repo with commitlint the most common error is that the commitmsg was wrong. In our case we have a npm run commit that triggers the cz-cli. So I would like to add a custom error message for this case that the programmer can use npm commit. CleanShot 2022-05-09 at 16 45 22@2x Thanks!

Manubi avatar May 09 '22 14:05 Manubi

I understand your usecase. I feel like people will always be surprised the first time they run into certain tools, i.e. commitlint, eslint, etc. Hard to find a technical feature solution for alle these cases.

Maybe adjusting the help-url will help already? You could point at your docs for the project where this part is explained. Also making it a point in your (project-)onboarding can help with this.

What do you think?

escapedcat avatar May 10 '22 06:05 escapedcat

Sure I can add it to the documentation... just wanted to make it a little bit more obvious. :) Thanks anyway!

Manubi avatar May 10 '22 14:05 Manubi

Do you know any tools which have this kind of feature? Would you be able to provide a PR? Maybe there is chance to think about it.

escapedcat avatar May 11 '22 01:05 escapedcat

Sorry, no idea. But I guess we could just add a custom error object to the config.

Manubi avatar May 12 '22 11:05 Manubi

[... ]we could just add a custom error object to the config.

One which would modify the error if commitlint is being used for the first time? Or a general one? Where would you expect this message top show up?

escapedcat avatar May 14 '22 02:05 escapedcat

[... ]we could just add a custom error object to the config.

One which would modify the error if commitlint is being used for the first time? Or a general one? Where would you expect this message top show up?

Yeah, if we can check if commitlint is installed it should show the error. Please use _pnpm commit_ to use commitlint. I would expect to show up everytime someone tries to commit without commitlint. :)

Manubi avatar May 17 '22 09:05 Manubi

Is it still unresolved ? I don't want to use the standard ones. ✖ subject may not be empty [subject-empty] ✖ type may not be empty [type-empty]

They give 0 information, which is not correct. Can I create my own messages? Without this, this tool becomes useless

alekcena avatar Feb 09 '23 19:02 alekcena

Any updates on whether or not this will be implemented? And if it will, any idea when? It would be super useful to output an example commit message rather than the regex being used to check it:

gitlint..................................................................Failed
- hook id: gitlint
- exit code: 1

1: T7 Title does not match regex (\[[A-Z|]*\] [A-Z]*-[A-Za-z0-9]* \| .*): "bad commit message"

Would be better for it to be something like:

gitlint..................................................................Failed
- hook id: gitlint
- exit code: 1

1: T7 Title does not match regex (\[[A-Z|]*\] [A-Z]*-[A-Za-z0-9]* \| .*): "bad commit message"
1: Example commit message format: "[WM] TICKET-10 | Some details"

Mo0rBy avatar Oct 04 '23 11:10 Mo0rBy

Is it still unresolved ? I don't want to use the standard ones. ✖ subject may not be empty [subject-empty] ✖ type may not be empty [type-empty]

They give 0 information, which is not correct. Can I create my own messages? Without this, this tool becomes useless

'use strict';

const expectedTypes = ['feat', 'fix', 'test', 'build', 'refactor', 'docs'];

module.exports = {
  // extends: ['@commitlint/config-conventional'],
  plugins: [
    {
      rules: {
        'custom-type-enum': ({ type }) => {
          if (!expectedTypes.includes(type)) {
            return [false,
              `
              Type must be one of: ${expectedTypes.join(', ')} \n
              Example: feat: add new feature
              `];
          }
          return [true];
        },
      },
    },
  ],
  rules: {
    'custom-type-enum': [2, 'always'],
  },
};

davidbo9omolov avatar Mar 12 '24 20:03 davidbo9omolov