diff --git a/@commitlint/lint/src/lint.test.ts b/@commitlint/lint/src/lint.test.ts index c8ff6cc123..c43cac2ede 100644 --- a/@commitlint/lint/src/lint.test.ts +++ b/@commitlint/lint/src/lint.test.ts @@ -5,9 +5,12 @@ test('throws without params', async () => { await expect(error).rejects.toThrow('Expected a raw commit'); }); -test('throws with empty message', async () => { - const error = (lint as any)(''); - await expect(error).rejects.toThrow('Expected a raw commit'); +test('positive on empty message', async () => { + expect(await lint('')).toMatchObject({ + valid: true, + errors: [], + warnings: [] + }); }); test('positive on stub message and no rule', async () => { diff --git a/@commitlint/lint/src/lint.ts b/@commitlint/lint/src/lint.ts index f216c7996e..242c91fdce 100644 --- a/@commitlint/lint/src/lint.ts +++ b/@commitlint/lint/src/lint.ts @@ -35,6 +35,21 @@ export default async function lint( // 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 allRules: Map | Rule> = new Map( Object.entries(defaultRules) );