Skip to content

Commit 9f92a74

Browse files
Carl Tompkinsmarionebl
Carl Tompkins
authored andcommitted
fix: ignore empty commit messages conventional-changelog#615
bypass rules for completely empty commit messages (only of blank lines/comments in message)
1 parent 9d14792 commit 9f92a74

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
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

+15
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ export default async function lint(
3535

3636
// Parse the commit message
3737
const parsed = await parse(message, undefined, opts.parserOpts);
38+
39+
if (
40+
parsed.header === null &&
41+
parsed.body === null &&
42+
parsed.footer === null
43+
) {
44+
// Commit is empty, skip
45+
return {
46+
valid: true,
47+
errors: [],
48+
warnings: [],
49+
input: message
50+
};
51+
}
52+
3853
const allRules: Map<string, Rule<unknown> | Rule<never>> = new Map(
3954
Object.entries(defaultRules)
4055
);

0 commit comments

Comments
 (0)