This repository has been archived by the owner. It is now read-only.
Validate commit messages
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci docs(README): add Circle CI badge and remove Coveralls Mar 25, 2018
.vscode refactor(*): update tslint config and add prettier Mar 25, 2018
bin feat(cli): add optional parameter to file COMMIT_EDITMSG Sep 6, 2017
conventions docs(conventions): add conventions since conventional-changelog remov… Mar 10, 2016
src refactor(test): apply prettier over test/* and fix deprecations Mar 25, 2018
test refactor(test): apply prettier over test/* and fix deprecations Mar 25, 2018
.editorconfig refactor(validate-commit): initial work to transition to TypeScript Mar 28, 2016
.gitignore feat(presets): update angular preset's commit types Dec 19, 2017
.prettierignore refactor(*): update tslint config and add prettier Mar 25, 2018
.prettierrc.json refactor(test): apply prettier over test/* and fix deprecations Mar 25, 2018
CHANGELOG.md chore(release): 3.4.0 Dec 19, 2017
LICENSE docs(license): update to Apache license Dec 2, 2015
README.md docs(README): add Circle CI badge and remove Coveralls Mar 25, 2018
example.gif docs(readme): use a gif Jun 20, 2016
gh-pages.js docs: add typedoc for initial documentation May 24, 2016
package.json chore(package): update @types/node to version 10.3.2 Jun 8, 2018
tsconfig.json fix(types): add dom to fix compilation error Nov 4, 2016
tslint.json refactor(*): update tslint config and add prettier Mar 25, 2018
yarn.lock docs(README): add Circle CI badge and remove Coveralls Mar 25, 2018

README.md

Validate Commit

Greenkeeper badge CircleCI

NPM version Downloads

Validate commit messages according to various presets

Install

npm install validate-commit --save-dev

Features

Even though there are a couple of other packages that do this, this one has a few quality of life changes.

  • Lets you decide how to validate the commit messages (see here)
  • It validate commit files coming from both strings and files
  • Supports the following presets:
  • Supports ignore patterns
  • Uses chalk module to color messages
  • Logging can be muted via SILENT environment variable

Usage

With Husky

E.g., using Husky.

"scripts": {
  "commitmsg": "validate-commit-msg"
}

From CLI

$ validate-commit-msg 'chore(package): some message'
$ validate-commit-msg -p eslint 'New: Awesome feature'
$ validate-commit-msg -p ember '[DOC beta] Update CONTRIBUTING.md'
$ validate-commit-msg -p jshint '[[DOCS]] Awesome JS docs'
$ ...

When a wrong commit message is given it outputs an explaination.

$ validate-commit-msg 'unknown(something): wrong'
# 'unknown' is not an allowed type!
# Valid types are: feat, fix, docs, style, refactor, perf, test, chore, revert

However you can mute it:

$ validate-commit-msg -s 'unknown(something): wrong'

Validate a commit with .git directory in another location

$ validate-commit-msg --mf ../../some/.git/module/COMMIT_EDITMSG

Within node

var validateCommit = require('validate-commit').validateMessage;
validateCommit('chore(package): some message'); // > true
validateCommit('New: Awesome', { preset: 'eslint' }); // > true
validateCommit('Unk: Awesome', { preset: 'eslint' }); // > false
// > The word "Unk" is not an allowed tag.
// > Valid types are: Fix, Update, Breaking, Docs, Build, New, Upgrade.
process.env.SILENT = true;
validateCommit('Unk: Awesome', { preset: 'eslint' }); // > false

API

JavaScript

validateMessage(message: string, ?options: object)
validateMessageFromFile(file: string, ?options: object)

CLI

This module, like many others, installs an executable in ./node_modules/.bin.

~./node_modules/.bin$ ./validate-commit-msg
  Usage: validate-commit-msg [options] [command]


  Commands:

    validate-commit-msg <message>  validate a message
    help [cmd]                     display help for [cmd]

  Validate commit messages according to various presets

  Options:

    -h, --help             output usage information
    -V, --version          output the version number
    -p, --preset <preset>  specify a preset (angular|atom|eslint|ember|jquery|jshint) [angular]
    -s, --silent           mute log messages [false]
    --mf --msgfile         relative path to COMMIT_EDITMSG file

Development

npm i

License

Apache-2.0 © Will Soto