Skip to content

Commit

Permalink
fix: subject-full-stop rule bugfix (#3531)
Browse files Browse the repository at this point in the history
* test(subject-full-stop): add two tests

* fix: subject-full-stop rule bugfix

Fixes #3530
  • Loading branch information
tehraninasab authored Feb 13, 2023
1 parent cfcd397 commit 5d3d529
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions @commitlint/rules/src/subject-full-stop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ const messages = {
empty: 'test:\n',
with: `test: subject.\n`,
without: `test: subject\n`,
standardScopeWith: `type(scope): subject.\n`,
nonStandardScopeWith: "type.scope: subject.\n"
};

const parsed = {
empty: parse(messages.empty),
with: parse(messages.with),
without: parse(messages.without),
standardScopeWith: parse(messages.standardScopeWith),
nonStandardScopeWith: parse(messages.nonStandardScopeWith),
};

test('empty against "always" should succeed', async () => {
Expand Down Expand Up @@ -48,3 +52,15 @@ test('without against "never ." should succeed', async () => {
const expected = true;
expect(actual).toEqual(expected);
});

test('commit message title with standard scope and full-stop against "never ." should fail', async () => {
const [actual] = subjectFullStop(await parsed.standardScopeWith, 'never', '.');
const expected = false;
expect(actual).toEqual(expected);
});

test('commit message title with non standard scope and full-stop against "never ." should fail', async () => {
const [actual] = subjectFullStop(await parsed.nonStandardScopeWith, 'never', '.');
const expected = false;
expect(actual).toEqual(expected);
});
6 changes: 4 additions & 2 deletions @commitlint/rules/src/subject-full-stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export const subjectFullStop: SyncRule<string> = (
when = 'always',
value = '.'
) => {
const input = parsed.subject;

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

const input = parsed.header;

const negated = when === 'never';
const hasStop = input[input.length - 1] === value;

Expand Down

0 comments on commit 5d3d529

Please sign in to comment.