Skip to content
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

Custom error message if commit format is wrong. #3165

Open
Manubi opened this issue May 9, 2022 · 10 comments
Open

Custom error message if commit format is wrong. #3165

Manubi opened this issue May 9, 2022 · 10 comments

Comments

@Manubi
Copy link
Contributor

Manubi commented May 9, 2022

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!

@escapedcat
Copy link
Member

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?

@Manubi
Copy link
Contributor Author

Manubi commented May 10, 2022

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

@escapedcat
Copy link
Member

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.

@Manubi
Copy link
Contributor Author

Manubi commented May 12, 2022

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

@escapedcat
Copy link
Member

escapedcat commented May 14, 2022

[... ]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?

@Manubi
Copy link
Contributor Author

Manubi commented May 17, 2022

[... ]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. :)

@alekcena
Copy link

alekcena commented Feb 9, 2023

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

@Mo0rBy
Copy link

Mo0rBy commented Oct 4, 2023

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"

@davidbo9omolov
Copy link

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'],
  },
};

@RogerHuauya
Copy link

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

No branches or pull requests

6 participants