diff --git a/@commitlint/lint/src/lint.test.ts b/@commitlint/lint/src/lint.test.ts index c8ff6cc123..2b5d0ef40f 100644 --- a/@commitlint/lint/src/lint.test.ts +++ b/@commitlint/lint/src/lint.test.ts @@ -283,3 +283,34 @@ test('returns original message with commit header, body and footer, parsing comm expect(report.input).toBe(expected); }); + +test('positive on comment-only commit message', async () => { + const actual = await lint( + // '# This is empty\n#This is also a comment', + '# comment!', + { + 'header-max-length': [2, 'always', 72] + }, + { + parserOpts: { + commentChar: '#' + } + } + ); + expect(actual.valid).toBe(true); +}); + +test('positive on blank lines and comment commit message', async () => { + const actual = await lint( + '\n# Comment\n# Another comment\n', + { + 'header-max-length': [2, 'always', 72] + }, + { + parserOpts: { + commentChar: '#' + } + } + ); + expect(actual.valid).toBe(true); +}); diff --git a/@commitlint/lint/src/lint.ts b/@commitlint/lint/src/lint.ts index 5ac511d9fa..40aa4b241d 100644 --- a/@commitlint/lint/src/lint.ts +++ b/@commitlint/lint/src/lint.ts @@ -9,14 +9,15 @@ import { LintOptions, LintRuleOutcome, Rule, - RuleSeverity + RuleSeverity, + LintOutcome } from '@commitlint/types'; export default async function lint( message: string, rawRulesConfig?: LintRuleConfig, rawOpts?: LintOptions -) { +): Promise { const opts = rawOpts ? rawOpts : {defaultIgnores: undefined, ignores: undefined}; @@ -36,6 +37,20 @@ 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) );