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 authored and marionebl committed Feb 7, 2020
1 parent 166cbb7 commit 9079ae4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
31 changes: 31 additions & 0 deletions @commitlint/lint/src/lint.test.ts
Expand Up @@ -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);
});
19 changes: 17 additions & 2 deletions @commitlint/lint/src/lint.ts
Expand Up @@ -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<LintOutcome> {
const opts = rawOpts
? rawOpts
: {defaultIgnores: undefined, ignores: undefined};
Expand All @@ -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<string, Rule<unknown> | Rule<never>> = new Map(
Object.entries(defaultRules)
);
Expand Down

0 comments on commit 9079ae4

Please sign in to comment.