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 subject-full-stop false positive when using ellipsis #3839

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
8 changes: 8 additions & 0 deletions @commitlint/rules/src/subject-full-stop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const messages = {
without: `test: subject\n`,
standardScopeWith: `type(scope): subject.\n`,
nonStandardScopeWith: 'type.scope: subject.\n',
ellipsisMessage: 'test: subject ends with ellipsis...',
};

const parsed = {
Expand All @@ -15,6 +16,7 @@ const parsed = {
without: parse(messages.without),
standardScopeWith: parse(messages.standardScopeWith),
nonStandardScopeWith: parse(messages.nonStandardScopeWith),
ellipsisMessage: parse(messages.ellipsisMessage),
};

test('empty against "always" should succeed', async () => {
Expand Down Expand Up @@ -72,3 +74,9 @@ test('commit message title with non standard scope and full-stop against "never
const expected = false;
expect(actual).toEqual(expected);
});

test('ellipsis is not fullstop so commit title ending with it against "never ." should not fail', async () => {
const [actual] = subjectFullStop(await parsed.ellipsisMessage, 'never', '.');
const expected = true;
expect(actual).toEqual(expected);
});
5 changes: 4 additions & 1 deletion @commitlint/rules/src/subject-full-stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export const subjectFullStop: SyncRule<string> = (
const input = parsed.header;

const negated = when === 'never';
const hasStop = input[input.length - 1] === value;
let hasStop = input[input.length - 1] === value;
if (input.slice(-3) === '...') {
hasStop = false;
}

return [
negated ? !hasStop : hasStop,
Expand Down