Skip to content

Commit

Permalink
fix(rules): footer-leading-blank should work with body comments (#3139)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtho authored Apr 28, 2022
1 parent 3e9c827 commit 7dd88c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 14 additions & 0 deletions @commitlint/rules/src/footer-leading-blank.test.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 7dd88c9

Please sign in to comment.