Skip to content

Commit

Permalink
fix: ignore empty commit messages #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 18, 2020
1 parent 9d14792 commit 9f92a74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 6 additions & 3 deletions @commitlint/lint/src/lint.test.ts
Expand Up @@ -5,9 +5,12 @@ test('throws without params', async () => {
await expect(error).rejects.toThrow('Expected a raw commit');
});

test('throws with empty message', async () => {
const error = (lint as any)('');
await expect(error).rejects.toThrow('Expected a raw commit');
test('positive on empty message', async () => {
expect(await lint('')).toMatchObject({
valid: true,
errors: [],
warnings: []
});
});

test('positive on stub message and no rule', async () => {
Expand Down
15 changes: 15 additions & 0 deletions @commitlint/lint/src/lint.ts
Expand Up @@ -35,6 +35,21 @@ 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 9f92a74

Please sign in to comment.