Skip to content

romeovs/sevenrules

 
 

Repository files navigation

sevenrules

Validates a git commit message against The seven rules:

  1. Separate subject from body with a blank line
  2. Limit the subject line to 72 characters
  3. Capitalize the subject line
  4. Do not end the subject line with a period
  5. Use the imperative mood in the subject line
  6. Wrap the body at 72 characters
  7. Use the body to explain what and why vs. how

The bolded rules 1-6 are checked. The remaining rule 7 is not detectable programmatically.

Rule 5 (Imperative mood) is heuristically checked using a blacklist of terms, but might give false negatives in some cases. The blacklist is based on this git hook.

The title of rule 2 says 50 characters but the body clarifies 72 is the hard limit.

A husky hook is provided for ease of use.

Inspired by the quality Bash implementation.

Usage

Installation through husky

Install husky and sevenrules:

npm install husky @romeovs/sevenrules --save-dev
# or
yarn add husky @romeovs/sevenrules --dev

Hook the validator to commit-msg in your package.json:

{
  "husky": {
    "hooks": {
      "commit-msg": "sevenrules"
    }
  }
}

Enjoy your clean commit log!

Manual installation

npm install --global husky @romeovs/sevenrules
# or
yarn global add  husky @romeovs/sevenrules

In the git repository you want to use sevenrules, add it to your commit-msg hook manually:

echo 'sevenrules "$@"' >> .git/hooks/commit-msg
chmod u+x .git/hooks/commit-msg

Enjoy your clean commit log!

Example

$ git commit -m "Updated README.md"
Your commit message breaks one of the seven rules of commit messages

  Rule 5: Use the imperative mood in the subject line

For more info on the seven rules, see https://chris.beams.io/posts/git-commit
commit-msg hook failed (add --no-verify to bypass)

Conduct

Respect agency. Follow the Code of Conduct.

License

Anybody caught using this work without our permission, will be mighty good friends of ourn, cause we don't give a dern. Study it. Hack it. Publish it, even without naming the source. We made it, that's all we wanted to do.

Released under the Severn license, an MIT derivative without the notice requirement. Contributor signatures available in the contributors repository.

NO rights reserved.

Packages

No packages published

Languages

  • JavaScript 100.0%