@@ -143,30 +143,31 @@ const getEmojiStrLength = (options: CommitizenGitOptions, type?: string): number
143143 return item ?. emoji ? item . emoji . length + 1 : 0 ;
144144} ;
145145
146+ const countLength = ( target : number , typeLength : number , scope : number , emojiLength : number ) =>
147+ target - typeLength - 2 - scope - emojiLength ;
148+
146149export const getMaxSubjectLength = (
147150 type : Answers [ "type" ] ,
148151 scope : Answers [ "scope" ] ,
149152 options : CommitizenGitOptions
150153) => {
151154 let optionMaxLength = Infinity ;
155+ const typeLength = type ?. length ? type . length : 0 ;
156+ const scopeLength = scope ? scope . length + 2 : 0 ;
157+ const emojiLength = options . useEmoji ? getEmojiStrLength ( options , type ) : 0 ;
152158 const maxHeaderLength = options ?. maxHeaderLength ? options ?. maxHeaderLength : Infinity ;
153159 const maxSubjectLength = options ?. maxSubjectLength ? options ?. maxSubjectLength : Infinity ;
154160 if ( options ?. maxHeaderLength === 0 || options ?. maxSubjectLength === 0 ) {
155161 return 0 ;
156162 } else if ( maxHeaderLength === Infinity ) {
157- optionMaxLength = maxSubjectLength !== Infinity ? maxSubjectLength : Infinity ;
163+ return maxSubjectLength !== Infinity ? maxSubjectLength : Infinity ;
158164 } else {
159- optionMaxLength = maxHeaderLength < maxSubjectLength ? maxHeaderLength : maxSubjectLength ;
165+ optionMaxLength =
166+ countLength ( maxHeaderLength , typeLength , scopeLength , emojiLength ) < maxSubjectLength
167+ ? maxHeaderLength
168+ : maxSubjectLength ;
160169 }
161- return (
162- optionMaxLength -
163- ( type ?. length ? type . length : 0 ) -
164- // `()`
165- ( scope ? scope . length + 2 : 0 ) -
166- // `: `
167- 2 -
168- ( options . useEmoji ? getEmojiStrLength ( options , type ) : 0 )
169- ) ;
170+ return countLength ( optionMaxLength , typeLength , scopeLength , emojiLength ) ;
170171} ;
171172
172173const filterCustomEmptyByOption = (
0 commit comments