Skip to content

Commit 1009f31

Browse files
author
Carl Tompkins
committed
fix: ignore empty commit messages #615
bypass rules for completely empty commit messages (only of blank lines/comments in message)
1 parent 4360d56 commit 1009f31

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

@commitlint/lint/src/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ export default async (message, rules = {}, opts = {}) => {
2828

2929
// Parse the commit message
3030
const parsed = await parse(message, undefined, opts.parserOpts);
31+
if (
32+
parsed.header === null &&
33+
parsed.body === null &&
34+
parsed.footer === null
35+
) {
36+
// Commit is empty, skip
37+
return {
38+
valid: true,
39+
errors: [],
40+
warnings: [],
41+
input: message
42+
};
43+
}
3144

3245
const mergedImplementations = Object.assign({}, implementations);
3346
if (opts.plugins) {

@commitlint/lint/src/index.test.js

+31
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,37 @@ test('positive on custom ignored message and broken rule', async t => {
6666
t.is(actual.input, ignoredMessage);
6767
});
6868

69+
test('positive on comment-only commit message', async t => {
70+
const actual = await lint(
71+
// '# This is empty\n#This is also a comment',
72+
'# comment!',
73+
{
74+
'header-max-length': [2, 'always', 72]
75+
},
76+
{
77+
parserOpts: {
78+
commentChar: '#'
79+
}
80+
}
81+
);
82+
t.true(actual.valid);
83+
});
84+
85+
test('positive on blank lines and comment commit message', async t => {
86+
const actual = await lint(
87+
'\n# Comment\n# Another comment\n',
88+
{
89+
'header-max-length': [2, 'always', 72]
90+
},
91+
{
92+
parserOpts: {
93+
commentChar: '#'
94+
}
95+
}
96+
);
97+
t.true(actual.valid);
98+
});
99+
69100
test('positive on stub message and opts', async t => {
70101
const actual = await lint(
71102
'foo-bar',

0 commit comments

Comments
 (0)