Skip to content

Commit 2c4ad8c

Browse files
committed
feat: allow empty scope
1 parent d026ace commit 2c4ad8c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/prompts/scope-maker.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,20 @@ describe('scopeMaker', () => {
5858
const scopeConfig = scopeMaker([], { 'scope-enum': [2, 'always', ['foo', 'bar']] })[0] as ListQuestion;
5959

6060
if (scopeConfig.choices) {
61-
expect(scopeConfig.choices).toEqual(['foo', 'bar']);
61+
expect(scopeConfig.choices).toEqual([
62+
{
63+
name: 'foo',
64+
value: 'foo'
65+
},
66+
{
67+
name: 'bar',
68+
value: 'bar'
69+
},
70+
{
71+
name: ':skip',
72+
value: ''
73+
}
74+
]);
6275
}
6376
});
6477
});

src/prompts/scope-maker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Rules } from '@commitlint/load';
2-
import { DistinctQuestion } from 'inquirer';
2+
import { ChoiceOptions } from 'inquirer';
33
import { whenFactory } from '../when';
44
import { caseValidator, emptyValidator, maxLengthValidator, minLengthValidator, validate } from '../validators';
55
import { wordCaseFilter } from '../filters';
@@ -37,11 +37,11 @@ export function validatorFactory(rules: Rules) {
3737
}
3838

3939
export function choicesFactory(rules: Rules) {
40-
let choices: string[] | undefined;
40+
let choices: ChoiceOptions[] | undefined;
4141
if (rules['scope-enum']) {
4242
const [, , scopeEnum] = rules['scope-enum'];
4343
if (scopeEnum && scopeEnum.length > 0) {
44-
choices = scopeEnum;
44+
choices = [...scopeEnum.map(scope => ({ name: scope, value: scope })), { name: ':skip', value: '' }];
4545
}
4646
}
4747

0 commit comments

Comments
 (0)