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): ignore comments in signed-off-by #2098

Merged
merged 1 commit into from
Sep 5, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions @commitlint/rules/src/signed-off-by.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ const messages = {
without: `test: subject\nbody\nfooter\n\n`,
inSubject: `test: subject Signed-off-by:\nbody\nfooter\n\n`,
inBody: `test: subject\nbody Signed-off-by:\nfooter\n\n`,
withSignoffAndComments: `test: subject

message body

Signed-off-by:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
`,
};

const parsed = {
Expand All @@ -15,6 +24,7 @@ const parsed = {
without: parse(messages.without),
inSubject: parse(messages.inSubject),
inBody: parse(messages.inBody),
withSignoffAndComments: parse(messages.withSignoffAndComments),
};

test('empty against "always signed-off-by" should fail', async () => {
Expand Down Expand Up @@ -57,6 +67,16 @@ test('without against "never signed-off-by" should succeed', async () => {
expect(actual).toEqual(expected);
});

test('trailing comments should be ignored', async () => {
const [actual] = signedOffBy(
await parsed.withSignoffAndComments,
'always',
'Signed-off-by:'
);
const expected = true;
expect(actual).toEqual(expected);
});

test('inSubject against "always signed-off-by" should fail', async () => {
const [actual] = signedOffBy(
await parsed.inSubject,
Expand Down
9 changes: 8 additions & 1 deletion @commitlint/rules/src/signed-off-by.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ export const signedOffBy: SyncRule<string> = (
when = 'always',
value = ''
) => {
const lines = toLines(parsed.raw).filter(Boolean);
const lines = toLines(parsed.raw).filter(
(ln) =>
// skip comments
!ln.startsWith('#') &&
// ignore empty lines
Boolean(ln)
);

const last = lines[lines.length - 1];

const negated = when === 'never';
Expand Down