Rules based on commit message
See original GitHub issueThis is a question/improvement. One issue I’m facing recently is with automated dependency updating and the long commit messages those can create. One example of such a message is chore(deps): update dependency https://github.com/homebrew/brew to v2.2.17 (#37)
, which is 80 characters long. I know that we can use the rules to statically change the header-max-length
in this case using something like this in our commitlint.config.js
.
"rules": {
"header-max-length": [0, "always", 100],
}
One downside, IMHO, with this is that it obviously changes it for all commits. I thought it would be nice if we can change header-max-length
, but only for certain commits. In this case those commits would have to start with chore(deps): update dependency
. By searching the issues I’ve found #303 and #397, which are somewhat related.
Expected Behavior
This sections describes how the rules functions would work with this improvement.
In this issue I want to suggest that the commit message is passed to rules that use a function. That would look something like shown below.
rules: {
'header-max-length': (commitMessage) => {
// commitMessage could be used to do whatever and return accordingly.
return [2, 'always', 100];
},
},
Using this, users should be able to create rules, based on commit messages. In the snippet below I’ve shown how this would look like for the issue I’m facing as described above.
rules: {
'header-max-length': (commitMessage) => {
if (commitMessage.startsWith('chore(deps): update dependency')) {
return [2, 'always', 100];
}
return [2, 'always', 72];
},
},
I think this improvement would also support the use-case described in #397 and in general give users more flexibility in defining rules.
Current Behavior
The difference from the current behaviour would be that the commit message is passed to rules functions.
Context
I’d be happy to help work on this with some pointers to where in the code-base the these changes would be.
Your Environment
Executable | Version |
---|---|
commitlint --version |
8.3.5 |
git --version |
2.26.0 |
node --version |
13.13.0 |
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
@jdbruijn no worries, feel free to comment on those issues and suggest to try your plugin.
I’m not completely sure, but maybe it would make sense to list plugins somewhere i.e. in this section.
Took a while 😝 but created a plugin to specify rules as functions. Using that resolved my specific issue.
https://github.com/vidavidorra/commitlint-plugin-function-rules
@escapedcat I think some open tickets here could benefit/be resolved by using my plugin, is it okay if I comment to those issues that using my plugin might be a solution for those cases and people? I don’t want to ‘promote’/spam those topics unsolicited 😉. I didn’t go through all issues so there might be more that would benefit from it, these are just tickets I ran into earlier when creating this ticket.