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 rule bugfix #3531

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions @commitlint/rules/src/subject-full-stop.test.ts
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"
escapedcat marked this conversation as resolved.
Show resolved Hide resolved
};

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
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