Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
fix(pattern): make commit matching pattern more true to the spec
Browse files Browse the repository at this point in the history
Make the commit message matching regular expression pattern more true to the
spec by:

* removing `fixup! ` as an allowed message prefix
* allowing any character except `)` and white space as scope name
* require a commit message subject
* remove unused pattern matching groups

BREAKING CHANGE: this removes `fixup!` as an allowedi commit message prefix and
requires the commit message subject to not be empty.

Signed-off-by: Hans Kristian Flaatten <[email protected]>
  • Loading branch information
Hans Kristian Flaatten committed Feb 5, 2016
1 parent 3b7d25f commit 259fb5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var semverRegex = require('semver-regex')

var config = getConfig();
var MAX_LENGTH = config.maxSubjectLength || 100;
var PATTERN = /^((?:fixup!\s*)?(\w*)(\(([\w\$\.\*/-]*)\))?\: (.*))(\n|$)/;
var PATTERN = /^((\w+)(?:\(([^\)\s]+)\))?: (.+))(?:\n|$)/;
var IGNORED = new RegExp(util.format('(^WIP)|(^%s$)', semverRegex().source));
var TYPES = config.types || ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'chore', 'revert'];

Expand Down Expand Up @@ -47,8 +47,8 @@ var validateMessage = function(message) {
} else {
var firstLine = match[1];
var type = match[2];
var scope = match[4];
var subject = match[5];
var scope = match[3];
var subject = match[4];

if (firstLine.length > MAX_LENGTH) {
error('is longer than %d characters !', MAX_LENGTH);
Expand Down
27 changes: 17 additions & 10 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ describe('validate-commit-msg.js', function() {
describe('validateMessage', function() {

it('should be valid', function() {
expect(m.validateMessage('fixup! fix($compile): something')).to.equal(VALID);
expect(m.validateMessage('fix($compile): something')).to.equal(VALID);
expect(m.validateMessage('feat($location): something')).to.equal(VALID);
expect(m.validateMessage('docs($filter): something')).to.equal(VALID);
expect(m.validateMessage('style($http): something')).to.equal(VALID);
expect(m.validateMessage('refactor($httpBackend): something')).to.equal(VALID);
expect(m.validateMessage('test($resource): something')).to.equal(VALID);
expect(m.validateMessage('chore($controller): something')).to.equal(VALID);
expect(m.validateMessage('chore(foo-bar): something')).to.equal(VALID);
expect(m.validateMessage('chore(*): something')).to.equal(VALID);
expect(m.validateMessage('chore(foo-bar): something')).to.equal(VALID);
expect(m.validateMessage('chore(guide/location): something')).to.equal(VALID);
expect(m.validateMessage('revert(foo): something')).to.equal(VALID);
expect(m.validateMessage('custom(baz): something')).to.equal(VALID);
expect(m.validateMessage('docs($filter): something')).to.equal(VALID);
expect(m.validateMessage('feat($location): something (another thing)')).to.equal(VALID);
expect(m.validateMessage('fix($compile): something')).to.equal(VALID);
expect(m.validateMessage('refactor($httpBackend): something')).to.equal(VALID);
expect(m.validateMessage('revert(foo): something')).to.equal(VALID);
expect(m.validateMessage('revert: feat($location): something')).to.equal(VALID);
expect(m.validateMessage('style($http): something')).to.equal(VALID);
expect(m.validateMessage('test($resource): something')).to.equal(VALID);

expect(errors).to.deep.equal([]);
expect(logs).to.deep.equal([]);
});
Expand Down Expand Up @@ -115,10 +116,17 @@ describe('validate-commit-msg.js', function() {
expect(logs).to.not.deep.equal([]);
});


it('should not allow msg prefixed with "fixup!"', function() {
expect(m.validateMessage('fixup! fix($compile): something')).to.equal(INVALID);
});


it('should handle undefined message"', function() {
expect(m.validateMessage()).to.equal(INVALID);
});


it('should allow semver style commits', function() {
expect(m.validateMessage('v1.0.0-alpha.1')).to.equal(VALID);
});
Expand All @@ -129,4 +137,3 @@ describe('validate-commit-msg.js', function() {
console.error = originalError;
});
});

0 comments on commit 259fb5d

Please sign in to comment.