Skip to content

Commit 7f702c2

Browse files
committed
fix: add breaking change leading empty line
1 parent 194240e commit 7f702c2

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/prompts/footer-maker.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { QualifiedRules } from '@commitlint/types';
2+
import type { Question as InquirerQuestion, Transformer } from 'inquirer';
23
import { valueFromRule, maxLengthTransformerFactory, pipeWith } from '../utils';
34
import type { Answers, Question } from '../commit-template';
45
import { validate, maxLengthValidator, minLengthValidator } from '../validators';
@@ -27,16 +28,29 @@ export function validatorFactory(rules: QualifiedRules): (value: string, answers
2728
};
2829
}
2930

30-
export function filterFactory(rules: QualifiedRules, prefix = '') {
31-
return (value: string): string =>
31+
export function breakingChangeFilterFactory(
32+
rules: QualifiedRules,
33+
prefix: string
34+
): InquirerQuestion<Answers>['filter'] {
35+
return value =>
3236
pipeWith<string>(
3337
value,
3438
v => prefix + v,
35-
v => leadingBlankFilter(v, rules['footer-leading-blank']),
36-
v => maxLineLengthFilter(v, rules['footer-max-line-length'])
39+
v => maxLineLengthFilter(v, rules['footer-max-line-length']),
40+
v => leadingBlankFilter(v, rules['footer-leading-blank'])
3741
);
3842
}
3943

44+
export function issueFilterFactory(rules: QualifiedRules): InquirerQuestion<Answers>['filter'] {
45+
return (value, answers): string => {
46+
return pipeWith<string>(
47+
value,
48+
v => maxLineLengthFilter(v, rules['footer-max-line-length']),
49+
v => (answers.isBreaking ? '\n\n' : '') + v
50+
);
51+
};
52+
}
53+
4054
export function breakingChangeMessageFactory(rules: QualifiedRules): () => string {
4155
return () => {
4256
const maxLength = valueFromRule(rules['footer-max-length']);
@@ -108,7 +122,7 @@ export function footerMaker(questions: Question[], rules: QualifiedRules): Quest
108122
when: answers => !!answers.isBreaking,
109123
validate: validatorFactory(rules),
110124
transformer: breakingTransformFactory(rules, BREAKING_CHANGE),
111-
filter: filterFactory(rules, BREAKING_CHANGE),
125+
filter: breakingChangeFilterFactory(rules, BREAKING_CHANGE),
112126
},
113127
{
114128
type: 'confirm',
@@ -124,7 +138,7 @@ export function footerMaker(questions: Question[], rules: QualifiedRules): Quest
124138
when: answers => isFixCommit(answers) || !!answers.isIssue,
125139
validate: validatorFactory(rules),
126140
transformer: issuesTransformerFactory(rules),
127-
filter: filterFactory(rules),
141+
filter: issueFilterFactory(rules),
128142
},
129143
];
130144

0 commit comments

Comments
 (0)