Skip to content

Commit 33ed2c0

Browse files
committed
fix(prompt): simplify logic used to compute maxLength
1 parent 02179c8 commit 33ed2c0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

@commitlint/prompt/src/library/get-prompt.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ export default function getPrompt(
6464
},
6565
tabCompletion: enumRule
6666
? enumRule[1][2].map((enumerable) => {
67-
const value = forceLeadingBlankFn(forceCaseFn(enumerable));
6867
const enumSettings = (settings.enumerables || {})[enumerable] || {};
6968
return {
70-
value: value,
69+
value: forceLeadingBlankFn(forceCaseFn(enumerable)),
7170
description: enumSettings.description || '',
7271
};
7372
})
@@ -92,13 +91,15 @@ export default function getPrompt(
9291
return prefix + EOL;
9392
},
9493
maxLength(res: Result) {
95-
const headerLength = settings.header ? settings.header.length : Infinity;
96-
const header = `${res.type}${res.scope ? `(${res.scope})` : ''}${
97-
res.type || res.scope ? ': ' : ''
98-
}${res.subject}`;
99-
const remainingHeaderLength = headerLength
100-
? headerLength - header.length
101-
: Infinity;
94+
let remainingHeaderLength = Infinity;
95+
if (settings.header && settings.header.length) {
96+
const header = format({
97+
type: res.type,
98+
scope: res.scope,
99+
subject: res.subject,
100+
});
101+
remainingHeaderLength = settings.header.length - header.length;
102+
}
102103
return Math.min(inputMaxLength, remainingHeaderLength);
103104
},
104105
transformer(value: string) {

0 commit comments

Comments
 (0)