Skip to content

Commit ff0111a

Browse files
byCedricmarionebl
authored andcommitted
fix(rules): include possible body offset in footer leading blank
1 parent 0ec63cc commit ff0111a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ export default (parsed, when) => {
88
}
99

1010
const negated = when === 'never';
11-
const [leading] = toLines(parsed.raw).slice(toLines(parsed.body).length + 1);
11+
const rawLines = toLines(parsed.raw);
12+
const bodyLines = toLines(parsed.body);
13+
const bodyOffset = bodyLines.length > 0 ? rawLines.indexOf(bodyLines[0]) : 1;
14+
const [leading] = rawLines.slice(bodyLines.length + bodyOffset);
1215

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

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

+16-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const messages = {
1111
'feat(new-parser): introduces a new parsing library\n\nBREAKING CHANGE: new library does not support foo-construct',
1212
with: 'test: subject\nbody\n\nBREAKING CHANGE: something important',
1313
withMulitLine:
14-
'test: subject\nmulti\nline\nbody\n\nBREAKING CHANGE: something important'
14+
'test: subject\nmulti\nline\nbody\n\nBREAKING CHANGE: something important',
15+
withDoubleNewLine: 'fix: some issue\n\ndetailed explanation\n\ncloses #123'
1516
};
1617

1718
const parsed = {
@@ -21,7 +22,8 @@ const parsed = {
2122
without: parse(messages.without),
2223
withoutBody: parse(messages.withoutBody),
2324
with: parse(messages.with),
24-
withMulitLine: parse(messages.withMulitLine)
25+
withMulitLine: parse(messages.withMulitLine),
26+
withDoubleNewLine: parse(messages.withDoubleNewLine)
2527
};
2628

2729
test('with simple message should succeed for empty keyword', async t => {
@@ -143,3 +145,15 @@ test('with blank line before footer and multiline body should succeed for "alway
143145
const expected = true;
144146
t.is(actual, expected);
145147
});
148+
149+
test('with double blank line before footer and double line in body should fail for "never"', async t => {
150+
const [actual] = footerLeadingBlank(await parsed.withDoubleNewLine, 'never');
151+
const expected = false;
152+
t.is(actual, expected);
153+
});
154+
155+
test('with double blank line before footer and double line in body should succeed for "always"', async t => {
156+
const [actual] = footerLeadingBlank(await parsed.withDoubleNewLine, 'always');
157+
const expected = true;
158+
t.is(actual, expected);
159+
});

0 commit comments

Comments
 (0)