From c3eb1a76e08213d7ce1f200e35f8d5d6de18982a Mon Sep 17 00:00:00 2001 From: Carl Tompkins Date: Tue, 18 Feb 2020 04:09:22 -0500 Subject: [PATCH] fix: ignore empty commit messages #615 (#676) * fix: ignore empty commit messages #615 bypass rules for completely empty commit messages (only of blank lines/comments in message) * fix: skip parsing for empty strings * style: apply autoformatting Co-authored-by: Mario Nebl --- @commitlint/lint/src/lint.test.ts | 9 ++++++--- @commitlint/lint/src/lint.ts | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/@commitlint/lint/src/lint.test.ts b/@commitlint/lint/src/lint.test.ts index 3104eb5fb7..52ef073c13 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 873f1484fa..6917d74611 100644 --- a/@commitlint/lint/src/lint.ts +++ b/@commitlint/lint/src/lint.ts @@ -36,7 +36,25 @@ export default async function lint( } // Parse the commit message - const parsed = await parse(message, undefined, opts.parserOpts); + const parsed = + message === '' + ? {header: null, body: null, footer: null} + : 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> = new Map( Object.entries(defaultRules) );