Skip to content

Commit

Permalink
fix: ignore empty commit messages conventional-changelog#615
Browse files Browse the repository at this point in the history
bypass rules for completely empty commit messages (only of blank
lines/comments in message)
  • Loading branch information
Carl Tompkins committed Jun 2, 2019
1 parent 4360d56 commit 1009f31
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions @commitlint/lint/src/index.js
Expand Up @@ -28,6 +28,19 @@ export default async (message, rules = {}, opts = {}) => {

// Parse the commit message
const parsed = await parse(message, undefined, opts.parserOpts);
if (
parsed.header === null &&
parsed.body === null &&
parsed.footer === null
) {
// Commit is empty, skip
return {
valid: true,
errors: [],
warnings: [],
input: message
};
}

const mergedImplementations = Object.assign({}, implementations);
if (opts.plugins) {
Expand Down
31 changes: 31 additions & 0 deletions @commitlint/lint/src/index.test.js
Expand Up @@ -66,6 +66,37 @@ test('positive on custom ignored message and broken rule', async t => {
t.is(actual.input, ignoredMessage);
});

test('positive on comment-only commit message', async t => {
const actual = await lint(
// '# This is empty\n#This is also a comment',
'# comment!',
{
'header-max-length': [2, 'always', 72]
},
{
parserOpts: {
commentChar: '#'
}
}
);
t.true(actual.valid);
});

test('positive on blank lines and comment commit message', async t => {
const actual = await lint(
'\n# Comment\n# Another comment\n',
{
'header-max-length': [2, 'always', 72]
},
{
parserOpts: {
commentChar: '#'
}
}
);
t.true(actual.valid);
});

test('positive on stub message and opts', async t => {
const actual = await lint(
'foo-bar',
Expand Down

0 comments on commit 1009f31

Please sign in to comment.