Skip to content

Commit c3eb1a7

Browse files
ctompmarionebl
andauthoredFeb 18, 2020
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 <marionebl@users.noreply.github.com>
1 parent 8b394c9 commit c3eb1a7

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed
 

‎@commitlint/lint/src/lint.test.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ test('throws without params', async () => {
55
await expect(error).rejects.toThrow('Expected a raw commit');
66
});
77

8-
test('throws with empty message', async () => {
9-
const error = (lint as any)('');
10-
await expect(error).rejects.toThrow('Expected a raw commit');
8+
test('positive on empty message', async () => {
9+
expect(await lint('')).toMatchObject({
10+
valid: true,
11+
errors: [],
12+
warnings: []
13+
});
1114
});
1215

1316
test('positive on stub message and no rule', async () => {

‎@commitlint/lint/src/lint.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,25 @@ export default async function lint(
3636
}
3737

3838
// Parse the commit message
39-
const parsed = await parse(message, undefined, opts.parserOpts);
39+
const parsed =
40+
message === ''
41+
? {header: null, body: null, footer: null}
42+
: await parse(message, undefined, opts.parserOpts);
43+
44+
if (
45+
parsed.header === null &&
46+
parsed.body === null &&
47+
parsed.footer === null
48+
) {
49+
// Commit is empty, skip
50+
return {
51+
valid: true,
52+
errors: [],
53+
warnings: [],
54+
input: message
55+
};
56+
}
57+
4058
const allRules: Map<string, BaseRule<never, RuleType>> = new Map(
4159
Object.entries(defaultRules)
4260
);

0 commit comments

Comments
 (0)
Please sign in to comment.