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(rules): footer-leading-blank should work with body comments #3139

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions @commitlint/rules/src/footer-leading-blank.test.ts
Expand Up @@ -8,6 +8,8 @@ const messages = {
without: 'test: subject\nbody\nBREAKING CHANGE: something important',
withoutBody:
'feat(new-parser): introduces a new parsing library\n\nBREAKING CHANGE: new library does not support foo-construct',
withBodyWithComment:
'feat(new-parser): introduces a new parsing library\n\nBody Line 1\n# comment\nBody Line 2\n\nBREAKING CHANGE: new library does not support foo-construct',
with: 'test: subject\nbody\n\nBREAKING CHANGE: something important',
withMulitLine:
'test: subject\nmulti\nline\nbody\n\nBREAKING CHANGE: something important',
Expand All @@ -20,6 +22,9 @@ const parsed = {
trailing: parse(messages.trailing),
without: parse(messages.without),
withoutBody: parse(messages.withoutBody),
withBodyWithComment: parse(messages.withBodyWithComment, undefined, {
commentChar: '#',
}),
with: parse(messages.with),
withMulitLine: parse(messages.withMulitLine),
withDoubleNewLine: parse(messages.withDoubleNewLine),
Expand Down Expand Up @@ -156,3 +161,12 @@ test('with double blank line before footer and double line in body should succee
const expected = true;
expect(actual).toEqual(expected);
});

test('with body containing comments should succeed for "always"', async () => {
const [actual] = footerLeadingBlank(
await parsed.withBodyWithComment,
'always'
);
const expected = true;
expect(actual).toEqual(expected);
});
6 changes: 3 additions & 3 deletions @commitlint/rules/src/footer-leading-blank.ts
Expand Up @@ -10,9 +10,9 @@ export const footerLeadingBlank: SyncRule = (parsed, when = 'always') => {

const negated = when === 'never';
const rawLines = toLines(parsed.raw);
const bodyLines = parsed.body ? toLines(parsed.body) : [];
const bodyOffset = bodyLines.length > 0 ? rawLines.indexOf(bodyLines[0]) : 1;
const [leading] = rawLines.slice(bodyLines.length + bodyOffset);
const footerLines = toLines(parsed.footer);
const footerOffset = rawLines.indexOf(footerLines[0]);
const [leading] = rawLines.slice(footerOffset - 1);

// Check if the first line of footer is empty
const succeeds = leading === '';
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -217,7 +217,7 @@ Features will only be applied to the current main version.

_Dates are subject to change._

We're not a sponsored OSS project. Therefor we can't promise that we will release patch versions for older releases in a timley manner.\
We're not a sponsored OSS project. Therefore we can't promise that we will release patch versions for older releases in a timely manner.\
If you are stuck on an older version and need a security patch we're happy if you can provide a PR.

## Related projects
Expand Down