Skip to content

Commit 7dd88c9

Browse files
authored
fix(rules): footer-leading-blank should work with body comments (#3139)
1 parent 3e9c827 commit 7dd88c9

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

@commitlint/rules/src/footer-leading-blank.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const messages = {
88
without: 'test: subject\nbody\nBREAKING CHANGE: something important',
99
withoutBody:
1010
'feat(new-parser): introduces a new parsing library\n\nBREAKING CHANGE: new library does not support foo-construct',
11+
withBodyWithComment:
12+
'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',
1113
with: 'test: subject\nbody\n\nBREAKING CHANGE: something important',
1214
withMulitLine:
1315
'test: subject\nmulti\nline\nbody\n\nBREAKING CHANGE: something important',
@@ -20,6 +22,9 @@ const parsed = {
2022
trailing: parse(messages.trailing),
2123
without: parse(messages.without),
2224
withoutBody: parse(messages.withoutBody),
25+
withBodyWithComment: parse(messages.withBodyWithComment, undefined, {
26+
commentChar: '#',
27+
}),
2328
with: parse(messages.with),
2429
withMulitLine: parse(messages.withMulitLine),
2530
withDoubleNewLine: parse(messages.withDoubleNewLine),
@@ -156,3 +161,12 @@ test('with double blank line before footer and double line in body should succee
156161
const expected = true;
157162
expect(actual).toEqual(expected);
158163
});
164+
165+
test('with body containing comments should succeed for "always"', async () => {
166+
const [actual] = footerLeadingBlank(
167+
await parsed.withBodyWithComment,
168+
'always'
169+
);
170+
const expected = true;
171+
expect(actual).toEqual(expected);
172+
});

@commitlint/rules/src/footer-leading-blank.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ export const footerLeadingBlank: SyncRule = (parsed, when = 'always') => {
1010

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

1717
// Check if the first line of footer is empty
1818
const succeeds = leading === '';

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ Features will only be applied to the current main version.
217217

218218
_Dates are subject to change._
219219

220-
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.\
220+
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.\
221221
If you are stuck on an older version and need a security patch we're happy if you can provide a PR.
222222

223223
## Related projects

0 commit comments

Comments
 (0)