question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rules based on commit message

See original GitHub issue

This 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
escapedcatcommented, Oct 20, 2020

@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.

1reaction
jdbruijncommented, Oct 19, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conventional Commits
The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an...
Read more >
Git Commit Messages: Best Practices & Guidelines
General Commit Message Guidelines ... As a general rule, your messages should start with a single line that's no more than about 50...
Read more >
How to Write Good Commit Messages: A Practical Git Guide
I'll only outline some general rules and tips for writing commit messages–you have to decide what convention you want to follow.
Read more >
Push rules - GitLab Docs
Use these rules for your commit messages. Require expression in commit messages: Messages must match the expression. To allow any commit message, leave...
Read more >
8.4 Customizing Git - An Example Git-Enforced Policy
Putting that in your update script will reject updates that contain commits that have messages that don't adhere to your rule. Enforcing a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found