diff --git a/@commitlint/cz-commitlint/src/SectionHeader.test.ts b/@commitlint/cz-commitlint/src/SectionHeader.test.ts index 6da978ff92..6b370b956a 100644 --- a/@commitlint/cz-commitlint/src/SectionHeader.test.ts +++ b/@commitlint/cz-commitlint/src/SectionHeader.test.ts @@ -55,10 +55,11 @@ describe('getQuestionConfig', () => { ); }); - test("should 'scope' supports multiple select separated with settings.scopeEnumSeparator", () => { + test("should 'scope' supports multiple select separated with settings.scopeEnumSeparator and enableMultipleScopes", () => { setPromptConfig({ settings: { scopeEnumSeparator: '/', + enableMultipleScopes: true, }, }); const config = getQuestionConfig('scope'); @@ -68,6 +69,11 @@ describe('getQuestionConfig', () => { }) ); }); + + test("should 'scope' disable multiple select by default", () => { + const config = getQuestionConfig('scope'); + expect(config).not.toContain('multipleSelectDefaultDelimiter'); + }); }); describe('combineCommitMessage', () => { diff --git a/@commitlint/cz-commitlint/src/SectionHeader.ts b/@commitlint/cz-commitlint/src/SectionHeader.ts index dfc71d80de..c3483cc79d 100644 --- a/@commitlint/cz-commitlint/src/SectionHeader.ts +++ b/@commitlint/cz-commitlint/src/SectionHeader.ts @@ -50,11 +50,6 @@ export function getQuestions(): Array { headerRuleFields.forEach((name) => { const questionConfig = getQuestionConfig(name); if (questionConfig) { - if (name === 'scope') { - questionConfig.multipleSelectDefaultDelimiter = - getPromptSettings()['scopeEnumSeparator']; - questionConfig.multipleValueDelimiters = /\/|\\|,/g; - } const instance = new HeaderQuestion( name, questionConfig, @@ -74,8 +69,11 @@ export function getQuestionConfig( if (questionConfig) { if (name === 'scope') { - questionConfig.multipleSelectDefaultDelimiter = - getPromptSettings()['scopeEnumSeparator']; + if (getPromptSettings()['enableMultipleScopes']) { + questionConfig.multipleSelectDefaultDelimiter = + getPromptSettings()['scopeEnumSeparator']; + } + // split scope string to segments, match commitlint rules questionConfig.multipleValueDelimiters = /\/|\\|,/g; } } diff --git a/@commitlint/cz-commitlint/src/store/defaultPromptConfigs.ts b/@commitlint/cz-commitlint/src/store/defaultPromptConfigs.ts index f2824dd2cf..e4a4ce8998 100644 --- a/@commitlint/cz-commitlint/src/store/defaultPromptConfigs.ts +++ b/@commitlint/cz-commitlint/src/store/defaultPromptConfigs.ts @@ -1,6 +1,7 @@ export default { settings: { scopeEnumSeparator: ',', + enableMultipleScopes: false, }, messages: { skip: '(press enter to skip)', diff --git a/@commitlint/cz-commitlint/src/store/prompts.test.ts b/@commitlint/cz-commitlint/src/store/prompts.test.ts index 799eb69d08..e02741c9f9 100644 --- a/@commitlint/cz-commitlint/src/store/prompts.test.ts +++ b/@commitlint/cz-commitlint/src/store/prompts.test.ts @@ -115,9 +115,7 @@ describe('setPromptConfig', () => { scopeEnumSeparator: '/', }, }); - expect(getPromptSettings()).toEqual({ - scopeEnumSeparator: '/', - }); + expect(getPromptSettings()['scopeEnumSeparator']).toEqual('/'); const processExit = jest .spyOn(process, 'exit') @@ -130,4 +128,13 @@ describe('setPromptConfig', () => { expect(processExit).toHaveBeenCalledWith(1); processExit.mockClear(); }); + + test('should pass on settings', () => { + setPromptConfig({ + settings: { + enableMultipleScopes: true, + }, + }); + expect(getPromptSettings()['enableMultipleScopes']).toEqual(true); + }); }); diff --git a/@commitlint/types/src/prompt.ts b/@commitlint/types/src/prompt.ts index 6e623ade87..25ca44385a 100644 --- a/@commitlint/types/src/prompt.ts +++ b/@commitlint/types/src/prompt.ts @@ -18,6 +18,7 @@ export type PromptName = export type PromptConfig = { settings: { scopeEnumSeparator: string; + enableMultipleScopes: boolean; }; messages: PromptMessages; questions: Partial< diff --git a/docs/reference-prompt.md b/docs/reference-prompt.md index 3d18f4fd0a..34a0f9ddba 100644 --- a/docs/reference-prompt.md +++ b/docs/reference-prompt.md @@ -8,35 +8,36 @@ There are three fields: `settings`, `messages` and `questions` Set optional options. -- scopeEnumSeparator: Commitlint supports [multiple scopes](./concepts-commit-conventions.md?id=multiple-scopes), you can specify the delimiter. +- `enableMultipleScopes`: `(boolean)` Enable multiple scopes, select scope with a radio list, disabled by default. +- `scopeEnumSeparator`: `(string)` Commitlint supports [multiple scopes](./concepts-commit-conventions.md?id=multiple-scopes), you can specify the delimiter.It is applied when `enableMultipleScopes` set true. ## `messages` Set hint contents, you can configure it to support localization. -- skip: The field can be skip by enter -- max: Maximum number of characters -- min: Minimum number of characters -- emptyWarning: The field can not be empty -- upperLimitWarning: The characters limit is exceeded -- lowerLimitWarning: The characters is less than lower limit +- `skip`: The field can be skip by enter +- `max`: Maximum number of characters +- `min`: Minimum number of characters +- `emptyWarning`: The field can not be empty +- `upperLimitWarning`: The characters limit is exceeded +- `lowerLimitWarning`: The characters is less than lower limit ## `questions` Specify the interactive steps, Steps can only be configure in -- header -- type -- scope -- subject -- body -- footer -- isBreaking -- breaking -- breakingBody -- isIssueAffected -- issues -- issuesBody +- `header` +- `type` +- `scope` +- `subject` +- `body` +- `footer` +- `isBreaking` +- `breaking` +- `breakingBody` +- `isIssueAffected` +- `issues` +- `issuesBody`
@@ -49,6 +50,7 @@ module.exports = { ... }, prompt: { + settings: {}, messages: { skip: ':skip', max: 'upper %d chars',