From 99d8881d0d951deded6d9e31bbb279d04101549b Mon Sep 17 00:00:00 2001 From: cherryblossom <31467609+cherryblossom000@users.noreply.github.com> Date: Sat, 17 Jul 2021 16:33:21 +1000 Subject: [PATCH] fix(cz-commitlint): fix minor formatting issues This commit adds a space after the title before the skip message and removes the double colon in the `config-conventional` type of change prompt. For example (when using `@commitlint/config-conventional`), the following would previously be printed: ``` Select the type of change that you're committing:: feat What is the scope of this change (e.g. component or file name)(press enter to skip): (max 96 chars) ``` Now with this change: ``` Select the type of change that you're committing: feat What is the scope of this change (e.g. component or file name) (press enter to skip): (max 96 chars) ``` --- @commitlint/config-conventional/index.js | 2 +- @commitlint/cz-commitlint/src/Question.test.ts | 8 ++++---- @commitlint/cz-commitlint/src/Question.ts | 14 ++++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/@commitlint/config-conventional/index.js b/@commitlint/config-conventional/index.js index b772bc333a..a2e917d344 100644 --- a/@commitlint/config-conventional/index.js +++ b/@commitlint/config-conventional/index.js @@ -36,7 +36,7 @@ module.exports = { prompt: { questions: { type: { - description: "Select the type of change that you're committing:", + description: "Select the type of change that you're committing", enum: { feat: { description: 'A new feature', diff --git a/@commitlint/cz-commitlint/src/Question.test.ts b/@commitlint/cz-commitlint/src/Question.test.ts index 9f94dfe90b..7a3cfb7d5b 100644 --- a/@commitlint/cz-commitlint/src/Question.test.ts +++ b/@commitlint/cz-commitlint/src/Question.test.ts @@ -102,7 +102,7 @@ describe('message', () => { enumList: ['cli', 'core'], }).question; expect(question).toHaveProperty('message', expect.any(Function)); - expect((question.message as any)()).toBe('please input: '); + expect((question.message as any)()).toBe('please input:'); }); test('should display skip hint when it is input and can skip', () => { @@ -112,7 +112,7 @@ describe('message', () => { }).question; expect(question).toHaveProperty('message', expect.any(Function)); expect((question.message as any)()).toBe( - 'please input(press enter to skip): \n' + 'please input (press enter to skip):\n' ); }); @@ -123,7 +123,7 @@ describe('message', () => { skip: true, } as any).question; expect(question).toHaveProperty('message', expect.any(Function)); - expect((question.message as any)()).toBe('please input: \n'); + expect((question.message as any)()).toBe('please input:\n'); }); test('should display upper limit hint when it is input and has max length', () => { @@ -155,7 +155,7 @@ describe('message', () => { } as any).question; expect(question).toHaveProperty('message', expect.any(Function)); expect((question.message as any)()).toBe( - 'please input(press enter to skip): 10 chars at least, upper 80 chars\n' + 'please input (press enter to skip): 10 chars at least, upper 80 chars\n' ); }); diff --git a/@commitlint/cz-commitlint/src/Question.ts b/@commitlint/cz-commitlint/src/Question.ts index 4abec6b53c..109db59ef8 100644 --- a/@commitlint/cz-commitlint/src/Question.ts +++ b/@commitlint/cz-commitlint/src/Question.ts @@ -176,11 +176,17 @@ export default class Question { return messages.join(', '); })(); - const skipMessage = this.skip ? this.getMessage('skip') : ''; - - return this.title + skipMessage + ': ' + countLimitMessage + '\n'; + const skipMessage = this.skip && this.getMessage('skip'); + + return ( + this.title + + (skipMessage ? ` ${skipMessage}` : '') + + ':' + + (countLimitMessage ? ` ${countLimitMessage}` : '') + + '\n' + ); } else { - return this.title + ': '; + return `${this.title}:`; } } }