Skip to content

Commit

Permalink
fix(rules): include possible body offset in footer leading blank
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric authored and marionebl committed Oct 5, 2018
1 parent 0ec63cc commit ff0111a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion @commitlint/rules/src/footer-leading-blank.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export default (parsed, when) => {
}

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

// Check if the first line of footer is empty
const succeeds = leading === '';
Expand Down
18 changes: 16 additions & 2 deletions @commitlint/rules/src/footer-leading-blank.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const messages = {
'feat(new-parser): introduces a new parsing library\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'
'test: subject\nmulti\nline\nbody\n\nBREAKING CHANGE: something important',
withDoubleNewLine: 'fix: some issue\n\ndetailed explanation\n\ncloses #123'
};

const parsed = {
Expand All @@ -21,7 +22,8 @@ const parsed = {
without: parse(messages.without),
withoutBody: parse(messages.withoutBody),
with: parse(messages.with),
withMulitLine: parse(messages.withMulitLine)
withMulitLine: parse(messages.withMulitLine),
withDoubleNewLine: parse(messages.withDoubleNewLine)
};

test('with simple message should succeed for empty keyword', async t => {
Expand Down Expand Up @@ -143,3 +145,15 @@ test('with blank line before footer and multiline body should succeed for "alway
const expected = true;
t.is(actual, expected);
});

test('with double blank line before footer and double line in body should fail for "never"', async t => {
const [actual] = footerLeadingBlank(await parsed.withDoubleNewLine, 'never');
const expected = false;
t.is(actual, expected);
});

test('with double blank line before footer and double line in body should succeed for "always"', async t => {
const [actual] = footerLeadingBlank(await parsed.withDoubleNewLine, 'always');
const expected = true;
t.is(actual, expected);
});

0 comments on commit ff0111a

Please sign in to comment.