Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore empty commit messages #615 #676

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions @commitlint/lint/src/lint.test.ts
Original file line number Diff line number Diff line change
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
20 changes: 19 additions & 1 deletion @commitlint/lint/src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,25 @@ export default async function lint(
}

// Parse the commit message
const parsed = await parse(message, undefined, opts.parserOpts);
const parsed =
message === ''
? {header: null, body: null, footer: null}
: 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, BaseRule<never, RuleType>> = new Map(
Object.entries(defaultRules)
);
Expand Down