Skip to content

Commit 5d3d529

Browse files
authored
fix: subject-full-stop rule bugfix (#3531)
* test(subject-full-stop): add two tests * fix: subject-full-stop rule bugfix Fixes #3530
1 parent cfcd397 commit 5d3d529

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

@commitlint/rules/src/subject-full-stop.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ const messages = {
55
empty: 'test:\n',
66
with: `test: subject.\n`,
77
without: `test: subject\n`,
8+
standardScopeWith: `type(scope): subject.\n`,
9+
nonStandardScopeWith: "type.scope: subject.\n"
810
};
911

1012
const parsed = {
1113
empty: parse(messages.empty),
1214
with: parse(messages.with),
1315
without: parse(messages.without),
16+
standardScopeWith: parse(messages.standardScopeWith),
17+
nonStandardScopeWith: parse(messages.nonStandardScopeWith),
1418
};
1519

1620
test('empty against "always" should succeed', async () => {
@@ -48,3 +52,15 @@ test('without against "never ." should succeed', async () => {
4852
const expected = true;
4953
expect(actual).toEqual(expected);
5054
});
55+
56+
test('commit message title with standard scope and full-stop against "never ." should fail', async () => {
57+
const [actual] = subjectFullStop(await parsed.standardScopeWith, 'never', '.');
58+
const expected = false;
59+
expect(actual).toEqual(expected);
60+
});
61+
62+
test('commit message title with non standard scope and full-stop against "never ." should fail', async () => {
63+
const [actual] = subjectFullStop(await parsed.nonStandardScopeWith, 'never', '.');
64+
const expected = false;
65+
expect(actual).toEqual(expected);
66+
});

@commitlint/rules/src/subject-full-stop.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ export const subjectFullStop: SyncRule<string> = (
66
when = 'always',
77
value = '.'
88
) => {
9-
const input = parsed.subject;
109

11-
if (!input) {
10+
let colonIndex = parsed.header.indexOf(':');
11+
if (colonIndex > 0 && colonIndex === parsed.header.length - 1) {
1212
return [true];
1313
}
1414

15+
const input = parsed.header;
16+
1517
const negated = when === 'never';
1618
const hasStop = input[input.length - 1] === value;
1719

0 commit comments

Comments
 (0)