Skip to content

Commit 9079ae4

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 166cbb7 commit 9079ae4

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

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

+31
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,34 @@ test('returns original message with commit header, body and footer, parsing comm
283283

284284
expect(report.input).toBe(expected);
285285
});
286+
287+
test('positive on comment-only commit message', async () => {
288+
const actual = await lint(
289+
// '# This is empty\n#This is also a comment',
290+
'# comment!',
291+
{
292+
'header-max-length': [2, 'always', 72]
293+
},
294+
{
295+
parserOpts: {
296+
commentChar: '#'
297+
}
298+
}
299+
);
300+
expect(actual.valid).toBe(true);
301+
});
302+
303+
test('positive on blank lines and comment commit message', async () => {
304+
const actual = await lint(
305+
'\n# Comment\n# Another comment\n',
306+
{
307+
'header-max-length': [2, 'always', 72]
308+
},
309+
{
310+
parserOpts: {
311+
commentChar: '#'
312+
}
313+
}
314+
);
315+
expect(actual.valid).toBe(true);
316+
});

@commitlint/lint/src/lint.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import {
99
LintOptions,
1010
LintRuleOutcome,
1111
Rule,
12-
RuleSeverity
12+
RuleSeverity,
13+
LintOutcome
1314
} from '@commitlint/types';
1415

1516
export default async function lint(
1617
message: string,
1718
rawRulesConfig?: LintRuleConfig,
1819
rawOpts?: LintOptions
19-
) {
20+
): Promise<LintOutcome> {
2021
const opts = rawOpts
2122
? rawOpts
2223
: {defaultIgnores: undefined, ignores: undefined};
@@ -36,6 +37,20 @@ export default async function lint(
3637

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

0 commit comments

Comments
 (0)