Skip to content

Commit

Permalink
fix: subject-full-stop false positive when using ellipsis (#3839)
Browse files Browse the repository at this point in the history
* test: using ellipses in titles ending

The SubjectFullStop failing test on
a title that ends with ellipsis.

* fix: subjectFullStop considering ellipsis
  • Loading branch information
Mersho authored Jan 4, 2024
1 parent 3ee4c28 commit b4246d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit b4246d6

Please sign in to comment.