Skip to content

Commit

Permalink
feat: you can add more subject help text below the subject descriptio…
Browse files Browse the repository at this point in the history
…n for issue#6
  • Loading branch information
孟陬 committed Mar 23, 2021
1 parent e7fde53 commit 8574b4a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions commit-msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ async function lint(commitMsgContent, config, lang) {

subjectDescriptions = defaultSubjectDescriptions,
invalidSubjectDescriptions = defaultInvalidSubjectDescriptions,

postSubjectDescriptions = [],
} = config;

verbose && debug('config:', config);
Expand All @@ -104,6 +106,8 @@ async function lint(commitMsgContent, config, lang) {
invalidScopeDescriptions,
subjectDescriptions,
invalidSubjectDescriptions,
postSubjectDescriptions,

lang,
})) {
process.exit(1);
Expand Down Expand Up @@ -190,6 +194,7 @@ function validateMessage(
scopeDescriptions,
invalidScopeDescriptions,
subjectDescriptions,
postSubjectDescriptions,
invalidSubjectDescriptions,
lang,
},
Expand Down Expand Up @@ -229,6 +234,7 @@ function validateMessage(
scopeDescriptions,
invalidScopeDescriptions,
subjectDescriptions,
postSubjectDescriptions,
invalidSubjectDescriptions,
lang,
},
Expand Down Expand Up @@ -265,6 +271,7 @@ function validateMessage(
scopeDescriptions,
invalidScopeDescriptions,
subjectDescriptions,
postSubjectDescriptions,
invalidSubjectDescriptions,
lang,
},
Expand Down Expand Up @@ -295,6 +302,7 @@ function displayError(
scopeDescriptions,
invalidScopeDescriptions,
subjectDescriptions,
postSubjectDescriptions,
invalidSubjectDescriptions,
lang,
},
Expand All @@ -318,6 +326,9 @@ function displayError(
const defaultInvalidScopeDescription = `scope can be ${emphasis('optional')}${RED}, but its parenthesis if exists cannot be empty.`;

const subjectDescription = subjectDescriptions.join('\n ');
let postSubjectDescription = postSubjectDescriptions.join('\n ');
postSubjectDescription = postSubjectDescription ? `\n\n ${italic(postSubjectDescription)}` : '';

const invalidSubjectDescription = invalidSubjectDescriptions.join('\n ');
const translated = i18n(lang);
const { example: labelExample, correctFormat, commitMessage } = translated;
Expand All @@ -340,7 +351,7 @@ function displayError(
${invalidScopeDescription || defaultInvalidScopeDescription}` : ''}
${invalidSubject ? RED : YELLOW}subject:
${GRAY}${subjectDescription}${invalidSubject ? `${RED}
${GRAY}${subjectDescription}${postSubjectDescription}${invalidSubject ? `${RED}
${invalidSubjectDescription}` : ''}
`,
);
Expand Down Expand Up @@ -450,11 +461,11 @@ function emphasis(text) {
* @param {string} text
* @returns {string}
*/
// function italic(text) {
// const ITALIC = '\x1b[3m';
function italic(text) {
const ITALIC = '\x1b[3m';

// return `${ITALIC}${text}${EOS}`;
// }
return `${ITALIC}${text}${EOS}`;
}

/**
* Make text underlined.
Expand Down

0 comments on commit 8574b4a

Please sign in to comment.