Skip to content

Commit 9d8d73f

Browse files
authored
feat(cz-commitlint): support select scope with radio list by setting disableMultipleScopes (#2911)
* feat(cz-commitlint): support select scope with radio list by setting disableMultipleScopes * feat(cz-commitlint): enableMultipleScopes default to false BREAKING CHANGE: users who is using multiple scopes need to set enableMultipleScopes to true #2782
1 parent 6b88fba commit 9d8d73f

File tree

6 files changed

+45
-30
lines changed

6 files changed

+45
-30
lines changed

@commitlint/cz-commitlint/src/SectionHeader.test.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ describe('getQuestionConfig', () => {
5555
);
5656
});
5757

58-
test("should 'scope' supports multiple select separated with settings.scopeEnumSeparator", () => {
58+
test("should 'scope' supports multiple select separated with settings.scopeEnumSeparator and enableMultipleScopes", () => {
5959
setPromptConfig({
6060
settings: {
6161
scopeEnumSeparator: '/',
62+
enableMultipleScopes: true,
6263
},
6364
});
6465
const config = getQuestionConfig('scope');
@@ -68,6 +69,11 @@ describe('getQuestionConfig', () => {
6869
})
6970
);
7071
});
72+
73+
test("should 'scope' disable multiple select by default", () => {
74+
const config = getQuestionConfig('scope');
75+
expect(config).not.toContain('multipleSelectDefaultDelimiter');
76+
});
7177
});
7278

7379
describe('combineCommitMessage', () => {

@commitlint/cz-commitlint/src/SectionHeader.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ export function getQuestions(): Array<DistinctQuestion> {
5050
headerRuleFields.forEach((name) => {
5151
const questionConfig = getQuestionConfig(name);
5252
if (questionConfig) {
53-
if (name === 'scope') {
54-
questionConfig.multipleSelectDefaultDelimiter =
55-
getPromptSettings()['scopeEnumSeparator'];
56-
questionConfig.multipleValueDelimiters = /\/|\\|,/g;
57-
}
5853
const instance = new HeaderQuestion(
5954
name,
6055
questionConfig,
@@ -74,8 +69,11 @@ export function getQuestionConfig(
7469

7570
if (questionConfig) {
7671
if (name === 'scope') {
77-
questionConfig.multipleSelectDefaultDelimiter =
78-
getPromptSettings()['scopeEnumSeparator'];
72+
if (getPromptSettings()['enableMultipleScopes']) {
73+
questionConfig.multipleSelectDefaultDelimiter =
74+
getPromptSettings()['scopeEnumSeparator'];
75+
}
76+
// split scope string to segments, match commitlint rules
7977
questionConfig.multipleValueDelimiters = /\/|\\|,/g;
8078
}
8179
}

@commitlint/cz-commitlint/src/store/defaultPromptConfigs.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export default {
22
settings: {
33
scopeEnumSeparator: ',',
4+
enableMultipleScopes: false,
45
},
56
messages: {
67
skip: '(press enter to skip)',

@commitlint/cz-commitlint/src/store/prompts.test.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ describe('setPromptConfig', () => {
115115
scopeEnumSeparator: '/',
116116
},
117117
});
118-
expect(getPromptSettings()).toEqual({
119-
scopeEnumSeparator: '/',
120-
});
118+
expect(getPromptSettings()['scopeEnumSeparator']).toEqual('/');
121119

122120
const processExit = jest
123121
.spyOn(process, 'exit')
@@ -130,4 +128,13 @@ describe('setPromptConfig', () => {
130128
expect(processExit).toHaveBeenCalledWith(1);
131129
processExit.mockClear();
132130
});
131+
132+
test('should pass on settings', () => {
133+
setPromptConfig({
134+
settings: {
135+
enableMultipleScopes: true,
136+
},
137+
});
138+
expect(getPromptSettings()['enableMultipleScopes']).toEqual(true);
139+
});
133140
});

@commitlint/types/src/prompt.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type PromptName =
1818
export type PromptConfig = {
1919
settings: {
2020
scopeEnumSeparator: string;
21+
enableMultipleScopes: boolean;
2122
};
2223
messages: PromptMessages;
2324
questions: Partial<

docs/reference-prompt.md

+21-19
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,36 @@ There are three fields: `settings`, `messages` and `questions`
88

99
Set optional options.
1010

11-
- scopeEnumSeparator: Commitlint supports [multiple scopes](./concepts-commit-conventions.md?id=multiple-scopes), you can specify the delimiter.
11+
- `enableMultipleScopes`: `(boolean)` Enable multiple scopes, select scope with a radio list, disabled by default.
12+
- `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.
1213

1314
## `messages`
1415

1516
Set hint contents, you can configure it to support localization.
1617

17-
- skip: The field can be skip by enter
18-
- max: Maximum number of characters
19-
- min: Minimum number of characters
20-
- emptyWarning: The field can not be empty
21-
- upperLimitWarning: The characters limit is exceeded
22-
- lowerLimitWarning: The characters is less than lower limit
18+
- `skip`: The field can be skip by enter
19+
- `max`: Maximum number of characters
20+
- `min`: Minimum number of characters
21+
- `emptyWarning`: The field can not be empty
22+
- `upperLimitWarning`: The characters limit is exceeded
23+
- `lowerLimitWarning`: The characters is less than lower limit
2324

2425
## `questions`
2526

2627
Specify the interactive steps, Steps can only be configure in
2728

28-
- header
29-
- type
30-
- scope
31-
- subject
32-
- body
33-
- footer
34-
- isBreaking
35-
- breaking
36-
- breakingBody
37-
- isIssueAffected
38-
- issues
39-
- issuesBody
29+
- `header`
30+
- `type`
31+
- `scope`
32+
- `subject`
33+
- `body`
34+
- `footer`
35+
- `isBreaking`
36+
- `breaking`
37+
- `breakingBody`
38+
- `isIssueAffected`
39+
- `issues`
40+
- `issuesBody`
4041

4142
<div class="sequence">
4243
<img src="./assets/cz-commitlint.png"/>
@@ -49,6 +50,7 @@ module.exports = {
4950
...
5051
},
5152
prompt: {
53+
settings: {},
5254
messages: {
5355
skip: ':skip',
5456
max: 'upper %d chars',

0 commit comments

Comments
 (0)