Skip to content

Commit 36f7431

Browse files
committed
fix: distribute newlines appropriately
1 parent ff372e0 commit 36f7431

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

@commitlint/cli/src/cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ async function main(options) {
211211
'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
212212
});
213213

214-
if (!flags.quiet) {
214+
if (!flags.quiet && output !== '') {
215215
console.log(output);
216216
}
217217

@commitlint/format/src/format.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@ 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)])
47+
.reduce((acc, item) => Array.isArray(item) ? [...acc, ...item] : [...acc, item], [])
4748
.join('\n');
4849
}
4950

5051
function formatInput(
5152
result: FormattableResult & WithInput,
5253
options: FormatOptions = {}
53-
): string {
54+
): string[] {
5455
const {color: enabled = true} = options;
5556
const {errors = [], warnings = [], input = ''} = result;
5657

5758
if (!input) {
58-
return '';
59+
return [''];
5960
}
6061

6162
const sign = '⧗';
@@ -66,8 +67,8 @@ function formatInput(
6667
const hasProblems = errors.length > 0 || warnings.length > 0;
6768

6869
return options.verbose || hasProblems
69-
? `${decoration} input: ${decoratedInput}`
70-
: '';
70+
? [`${decoration} input: ${decoratedInput}`]
71+
: [];
7172
}
7273

7374
export function formatResult(
@@ -97,13 +98,25 @@ export function formatResult(
9798
const deco = enabled ? (chalk[color] as any)(sign) : sign;
9899
const el = errors.length;
99100
const wl = warnings.length;
100-
const hasProblems = errors.length > 0 || warnings.length > 0;
101+
const hasProblems = problems.length > 0;
102+
103+
const summary =
104+
options.verbose || hasProblems
105+
? `${deco} found ${el} problems, ${wl} warnings`
106+
: undefined;
107+
108+
const fmtSummary =
109+
enabled && typeof summary === 'string' ? chalk.bold(summary) : summary;
101110

102-
const summary = (options.verbose || hasProblems) ? `${deco} found ${el} problems, ${wl} warnings` : undefined;
103-
const fmtSummary = enabled && typeof summary === 'string' ? chalk.bold(summary) : summary;
104111
const help = hasProblems ? `ⓘ Get help: ${options.helpUrl}` : undefined;
105112

106-
return [...problems, '', fmtSummary, help].filter((line): line is string => typeof line === 'string');
113+
return [
114+
...problems,
115+
hasProblems ? '' : undefined,
116+
fmtSummary,
117+
help,
118+
help ? '' : undefined
119+
].filter((line): line is string => typeof line === 'string');
107120
}
108121

109122
export default format;

0 commit comments

Comments
 (0)