Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cz-commitlint): support select scope with radio list by setting disableMultipleScopes #2911

Merged
merged 2 commits into from Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion @commitlint/cz-commitlint/src/SectionHeader.test.ts
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
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
@@ -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
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
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
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