Skip to content

ngx-devs/commitlint-plugin-imperative

Repository files navigation

Commitlint Imperative Plugin

A Commitlint plugin to ensure that commits are made using imperative mood.

Build NPM Version Install Size Top Language GitHub last commit License

AboutInstallationUsageAuthorLicense

ℹ️ About

If you want to write a git commit message properly, you should use the imperative mood. This means you need to eliminate the temptation to use gerunds or past tense in your subject lines.

Use the imperative mood. It is easier to read and scan quickly:

We use imperative mood because it's going to complete the sentence “If applied, this commit will …” (e.g. “If applied, this commit will add alert admin for new user registration”).

Using imperative mood and not past tense in commit messages has made a big thread of discussions between developers over the question “Why should it be present tense?”.

The reason behind using present tense is that the commit message is answering the question “What will happen after the commit is applied?”. If we think of a commit as an independent patch, it doesn’t matter if it applied in the past. What matters is that this patch is always supposed to make that particular change when it’s applied.

Even Git itself suggests and uses imperative mood in commit messages in Documentation/SubmittingPatches

For example, the default message created when using git merge reads:

Merge branch 'feature/login'

And when using git revert:

Revert "Add the thing with the stuff"
This reverts commit cc87791524aedd593cff5a74532befe7ab69ce9d.

Or when clicking the “Merge” button on a GitHub pull request:

Merge pull request #123 from someuser/somebranch

Use this plugin to enforce this rule.


▶️ Installation

#install
npm install -D @ngx-devs/commitlint-plugin-imperative

🤖 Usage

imperative-rule/en

Set your commitlint config to:

{
    plugins: ["@ngx-devs/commitlint-plugin-imperative"],
    rules: {
        "imperative-rule/en": [2, "always", ]
    }
}
imperative-rule/pt-br

Set your commitlint config to:

{
    plugins: ["@ngx-devs/commitlint-plugin-imperative"],
    rules: {
        "imperative-rule/pt-br": [2, "always", ]
    }
}

✍️ Examples

imperative-rule/en

$ git commit -m "adding a project"

⧗   input: adding a project
✖   This commit is in gerund. Please use the imperative form. [imperative-rule/en]

✖   found 1 problems, 0 warnings

$ git commit -m "added new project"

⧗   input: added new project
✖   This commit is in past tense. Please use the imperative form. [imperative-rule/en]

✖   found 1 problems, 0 warnings

imperative-rule/pt-br

$ git commit -m "adicionando autenticação"

⧗   input: adicionando autenticação
✖   This commit is in gerund. Please use the imperative form. [imperative-rule/pt-br]

✖   found 1 problems, 0 warnings

$ git commit -m "adicionado autenticação"

⧗   input: adicionado autenticação
✖   This commit is in past tense. Please use the imperative form. [imperative-rule/pt-br]

✖   found 1 problems, 0 warnings

👦 Author

Profile Photo Gleison Almeida
Gleison de Almeida

Developed with ❤️ by Gleison Almeida
👋🏽 My Contacts:

Linkedin Badge Github Badge Outlook Badge


⚖️ License

Copyright © 2021 Gleison Almeida.
This project is licensed by MIT.