commitlint
commitlint copied to clipboard
Custom error message if commit format is wrong.
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.
Thanks!
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?
Sure I can add it to the documentation... just wanted to make it a little bit more obvious. :) Thanks anyway!
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.
Sorry, no idea. But I guess we could just add a custom error object to the config.
[... ]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?
[... ]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. :)
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
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"
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'],
},
};