Skip to content

Commit

Permalink
feat(cz-commitlint): support select scope with radio list by setting …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
curly210102 authored Dec 9, 2021
1 parent 6b88fba commit 9d8d73f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 30 deletions.
8 changes: 7 additions & 1 deletion @commitlint/cz-commitlint/src/SectionHeader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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', () => {
Expand Down
12 changes: 5 additions & 7 deletions @commitlint/cz-commitlint/src/SectionHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ export function getQuestions(): Array<DistinctQuestion> {
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,
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default {
settings: {
scopeEnumSeparator: ',',
enableMultipleScopes: false,
},
messages: {
skip: '(press enter to skip)',
Expand Down
13 changes: 10 additions & 3 deletions @commitlint/cz-commitlint/src/store/prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ describe('setPromptConfig', () => {
scopeEnumSeparator: '/',
},
});
expect(getPromptSettings()).toEqual({
scopeEnumSeparator: '/',
});
expect(getPromptSettings()['scopeEnumSeparator']).toEqual('/');

const processExit = jest
.spyOn(process, 'exit')
Expand All @@ -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);
});
});
1 change: 1 addition & 0 deletions @commitlint/types/src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type PromptName =
export type PromptConfig = {
settings: {
scopeEnumSeparator: string;
enableMultipleScopes: boolean;
};
messages: PromptMessages;
questions: Partial<
Expand Down
40 changes: 21 additions & 19 deletions docs/reference-prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

<div class="sequence">
<img src="./assets/cz-commitlint.png"/>
Expand All @@ -49,6 +50,7 @@ module.exports = {
...
},
prompt: {
settings: {},
messages: {
skip: ':skip',
max: 'upper %d chars',
Expand Down

0 comments on commit 9d8d73f

Please sign in to comment.