Skip to content

Commit 3a4f150

Browse files
committed
fix: avoid summary for success cases
1 parent 444bc97 commit 3a4f150

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

@commitlint/format/src/format.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,10 @@ test('uses signs as configured', () => {
138138
expect(actualWarning).toContain('WRN');
139139
});
140140

141-
test('format result provides summary without arguments', () => {
141+
test('format result is empty without arguments', () => {
142142
const actual = formatResult();
143143
const actualText = actual.join('\n');
144-
145-
expect(actualText).toContain('0 problems, 0 warnings');
144+
expect(actualText).toBe('');
146145
});
147146

148147
test('format result transforms error to text', () => {

@commitlint/format/src/format.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function format(
4343

4444
return results
4545
.filter(r => Array.isArray(r.warnings) || Array.isArray(r.errors))
46-
.map(result => [fi(result), fr(result), ''].join('\n'))
46+
.map(result => [fi(result), ...fr(result)].join('\n'))
4747
.join('\n');
4848
}
4949

@@ -52,7 +52,7 @@ function formatInput(
5252
options: FormatOptions = {}
5353
): string {
5454
const {color: enabled = true} = options;
55-
const {errors = [], input = ''} = result;
55+
const {errors = [], warnings = [], input = ''} = result;
5656

5757
if (!input) {
5858
return '';
@@ -63,8 +63,11 @@ function formatInput(
6363
const commitText = errors.length > 0 ? input : input.split('\n')[0];
6464

6565
const decoratedInput = enabled ? chalk.bold(commitText) : commitText;
66+
const hasProblems = errors.length > 0 || warnings.length > 0;
6667

67-
return `${decoration} input: ${decoratedInput}`;
68+
return options.verbose || hasProblems
69+
? `${decoration} input: ${decoratedInput}`
70+
: '';
6871
}
6972

7073
export function formatResult(
@@ -94,18 +97,13 @@ export function formatResult(
9497
const deco = enabled ? (chalk[color] as any)(sign) : sign;
9598
const el = errors.length;
9699
const wl = warnings.length;
97-
const needsHelp = errors.length > 0 || warnings.length > 0;
100+
const hasProblems = errors.length > 0 || warnings.length > 0;
98101

99-
const lines = [
100-
`${deco} found ${el} problems, ${wl} warnings`,
101-
options.helpUrl && needsHelp ? `Get help: ${options.helpUrl}` : undefined
102-
];
102+
const summary = (options.verbose || hasProblems) ? `${deco} found ${el} problems, ${wl} warnings` : undefined;
103+
const fmtSummary = enabled && typeof summary === 'string' ? chalk.bold(summary) : summary;
104+
const help = hasProblems ? `ⓘ Get help: ${options.helpUrl}` : undefined;
103105

104-
const summary = lines
105-
.filter(line => typeof line === 'string')
106-
.join('\n');
107-
108-
return [...problems, enabled ? chalk.bold(summary) : summary];
106+
return [...problems, '', fmtSummary, help].filter((line): line is string => typeof line === 'string');
109107
}
110108

111109
export default format;

0 commit comments

Comments
 (0)