From 9f92a7422063b41d77af910d56dac70681be5b38 Mon Sep 17 00:00:00 2001 From: Carl Tompkins Date: Sun, 2 Jun 2019 11:37:43 -0400 Subject: [PATCH 1/3] fix: ignore empty commit messages #615 bypass rules for completely empty commit messages (only of blank lines/comments in message) --- @commitlint/lint/src/lint.test.ts | 9 ++++++--- @commitlint/lint/src/lint.ts | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) 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) ); From c8252868d637dce6fd4aed34d849c299a7ff971f Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Tue, 18 Feb 2020 19:58:09 +1100 Subject: [PATCH 2/3] fix: skip parsing for empty strings --- @commitlint/lint/src/lint.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/@commitlint/lint/src/lint.ts b/@commitlint/lint/src/lint.ts index f8cb193f93..a0fc5d0d78 100644 --- a/@commitlint/lint/src/lint.ts +++ b/@commitlint/lint/src/lint.ts @@ -36,7 +36,9 @@ 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 && From 267cc6e7a2a4c27a7ce4d26dc90b214c900339e3 Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Tue, 18 Feb 2020 20:02:39 +1100 Subject: [PATCH 3/3] style: apply autoformatting --- @commitlint/lint/src/lint.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/@commitlint/lint/src/lint.ts b/@commitlint/lint/src/lint.ts index a0fc5d0d78..6917d74611 100644 --- a/@commitlint/lint/src/lint.ts +++ b/@commitlint/lint/src/lint.ts @@ -36,9 +36,10 @@ export default async function lint( } // Parse the commit message - const parsed = message === '' - ? { header: null, body: null, footer: null } - : 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 &&