From 24fd64b4aefdbbb08c808070669102066f400600 Mon Sep 17 00:00:00 2001 From: Curly Brackets Date: Thu, 9 Dec 2021 12:28:51 +0800 Subject: [PATCH 1/2] feat(cz-commitlint): support select scope with radio list by setting disableMultipleScopes --- .../cz-commitlint/src/SectionHeader.test.ts | 10 +++++ .../cz-commitlint/src/SectionHeader.ts | 12 +++--- .../src/store/defaultPromptConfigs.ts | 1 + .../cz-commitlint/src/store/prompts.test.ts | 13 ++++-- @commitlint/types/src/prompt.ts | 1 + docs/reference-prompt.md | 40 ++++++++++--------- 6 files changed, 48 insertions(+), 29 deletions(-) diff --git a/@commitlint/cz-commitlint/src/SectionHeader.test.ts b/@commitlint/cz-commitlint/src/SectionHeader.test.ts index 6da978ff92..0ec2146baf 100644 --- a/@commitlint/cz-commitlint/src/SectionHeader.test.ts +++ b/@commitlint/cz-commitlint/src/SectionHeader.test.ts @@ -68,6 +68,16 @@ describe('getQuestionConfig', () => { }) ); }); + + test("should 'scope' disable multiple select with disableMultipleScopes", () => { + setPromptConfig({ + settings: { + disableMultipleScopes: true, + }, + }); + 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..0303208ad7 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()['disableMultipleScopes']) { + 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..1423699ec4 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: ',', + disableMultipleScopes: 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..51ae30711c 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: { + disableMultipleScopes: true, + }, + }); + expect(getPromptSettings()['disableMultipleScopes']).toEqual(true); + }); }); diff --git a/@commitlint/types/src/prompt.ts b/@commitlint/types/src/prompt.ts index 6e623ade87..3db63005e1 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; + disableMultipleScopes: boolean; }; messages: PromptMessages; questions: Partial< diff --git a/docs/reference-prompt.md b/docs/reference-prompt.md index 3d18f4fd0a..739f9c1f02 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. +- `scopeEnumSeparator`: `(string)` Commitlint supports [multiple scopes](./concepts-commit-conventions.md?id=multiple-scopes), you can specify the delimiter. +- `disableMultipleScopes`: `(boolean)` Disable multiple scopes, select scope with a radio list. ## `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', From bae9ea2e880d694f58cfed4eae3921ff41890faa Mon Sep 17 00:00:00 2001 From: Curly Brackets Date: Thu, 9 Dec 2021 15:48:45 +0800 Subject: [PATCH 2/2] feat(cz-commitlint): enableMultipleScopes default to false BREAKING CHANGE: users who is using multiple scopes need to set enableMultipleScopes to true #2782 --- @commitlint/cz-commitlint/src/SectionHeader.test.ts | 10 +++------- @commitlint/cz-commitlint/src/SectionHeader.ts | 2 +- .../cz-commitlint/src/store/defaultPromptConfigs.ts | 2 +- @commitlint/cz-commitlint/src/store/prompts.test.ts | 4 ++-- @commitlint/types/src/prompt.ts | 2 +- docs/reference-prompt.md | 4 ++-- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/@commitlint/cz-commitlint/src/SectionHeader.test.ts b/@commitlint/cz-commitlint/src/SectionHeader.test.ts index 0ec2146baf..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'); @@ -69,12 +70,7 @@ describe('getQuestionConfig', () => { ); }); - test("should 'scope' disable multiple select with disableMultipleScopes", () => { - setPromptConfig({ - settings: { - disableMultipleScopes: true, - }, - }); + test("should 'scope' disable multiple select by default", () => { const config = getQuestionConfig('scope'); expect(config).not.toContain('multipleSelectDefaultDelimiter'); }); diff --git a/@commitlint/cz-commitlint/src/SectionHeader.ts b/@commitlint/cz-commitlint/src/SectionHeader.ts index 0303208ad7..c3483cc79d 100644 --- a/@commitlint/cz-commitlint/src/SectionHeader.ts +++ b/@commitlint/cz-commitlint/src/SectionHeader.ts @@ -69,7 +69,7 @@ export function getQuestionConfig( if (questionConfig) { if (name === 'scope') { - if (!getPromptSettings()['disableMultipleScopes']) { + if (getPromptSettings()['enableMultipleScopes']) { questionConfig.multipleSelectDefaultDelimiter = getPromptSettings()['scopeEnumSeparator']; } diff --git a/@commitlint/cz-commitlint/src/store/defaultPromptConfigs.ts b/@commitlint/cz-commitlint/src/store/defaultPromptConfigs.ts index 1423699ec4..e4a4ce8998 100644 --- a/@commitlint/cz-commitlint/src/store/defaultPromptConfigs.ts +++ b/@commitlint/cz-commitlint/src/store/defaultPromptConfigs.ts @@ -1,7 +1,7 @@ export default { settings: { scopeEnumSeparator: ',', - disableMultipleScopes: false, + 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 51ae30711c..e02741c9f9 100644 --- a/@commitlint/cz-commitlint/src/store/prompts.test.ts +++ b/@commitlint/cz-commitlint/src/store/prompts.test.ts @@ -132,9 +132,9 @@ describe('setPromptConfig', () => { test('should pass on settings', () => { setPromptConfig({ settings: { - disableMultipleScopes: true, + enableMultipleScopes: true, }, }); - expect(getPromptSettings()['disableMultipleScopes']).toEqual(true); + expect(getPromptSettings()['enableMultipleScopes']).toEqual(true); }); }); diff --git a/@commitlint/types/src/prompt.ts b/@commitlint/types/src/prompt.ts index 3db63005e1..25ca44385a 100644 --- a/@commitlint/types/src/prompt.ts +++ b/@commitlint/types/src/prompt.ts @@ -18,7 +18,7 @@ export type PromptName = export type PromptConfig = { settings: { scopeEnumSeparator: string; - disableMultipleScopes: boolean; + enableMultipleScopes: boolean; }; messages: PromptMessages; questions: Partial< diff --git a/docs/reference-prompt.md b/docs/reference-prompt.md index 739f9c1f02..34a0f9ddba 100644 --- a/docs/reference-prompt.md +++ b/docs/reference-prompt.md @@ -8,8 +8,8 @@ There are three fields: `settings`, `messages` and `questions` Set optional options. -- `scopeEnumSeparator`: `(string)` Commitlint supports [multiple scopes](./concepts-commit-conventions.md?id=multiple-scopes), you can specify the delimiter. -- `disableMultipleScopes`: `(boolean)` Disable multiple scopes, select scope with a radio list. +- `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`