From f0d8c53319915bce17378e81b14065fef25c1d95 Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Sat, 23 Apr 2022 16:06:14 +0800 Subject: [PATCH] fix(cz-git): fix custom scope skip allowEmptyScopes check link #16 --- packages/cz-git/src/loader.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/cz-git/src/loader.ts b/packages/cz-git/src/loader.ts index 4bdfab928..1260f28db 100644 --- a/packages/cz-git/src/loader.ts +++ b/packages/cz-git/src/loader.ts @@ -135,6 +135,10 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => { name: "scope", message: options.messages?.customScope, default: options.defaultScope || undefined, + validate(input: string) { + if (options.allowEmptyScopes) return true; + return input.length ? true : "\u001B[1;31m[ERROR] scope is required\u001B[0m"; + }, when(answers: Answers) { return answers.scope === "___CUSTOM___"; } @@ -170,14 +174,14 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => { else tooltip = `${maxSubjectLength - subjectLength} more chars allowed`; const tooltipColor = minSubjectLength !== undefined && - subjectLength >= minSubjectLength && - subjectLength <= maxSubjectLength + subjectLength >= minSubjectLength && + subjectLength <= maxSubjectLength ? "\u001B[90m" : "\u001B[31m"; const subjectColor = minSubjectLength !== undefined && - subjectLength >= minSubjectLength && - subjectLength <= maxSubjectLength + subjectLength >= minSubjectLength && + subjectLength <= maxSubjectLength ? "\u001B[36m" : "\u001B[31m"; @@ -229,7 +233,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => { options.customIssuePrefixsAlias, options.allowCustomIssuePrefixs, options.allowEmptyIssuePrefixs - ) + ); return issues?.filter((item) => (input ? item.name?.includes(input) : true)) || true; } },