Skip to content

Commit 253d1ce

Browse files
byCedricmarionebl
authored andcommitted
refactor(cli): lint all messages in parallel before output
1 parent 4eda933 commit 253d1ce

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

@commitlint/cli/src/cli.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,30 @@ async function main(options) {
141141
opts.parserOpts.commentChar = '#';
142142
}
143143

144-
return Promise.all(
145-
messages.map(async message => {
146-
const report = await lint(message, loaded.rules, opts);
147-
const formatted = format(report, {color: flags.color});
148-
const input =
149-
report.errors.length > 0
150-
? `\n${report.input}\n`
151-
: message.split('\n')[0];
152-
153-
if (!flags.quiet) {
154-
console.log(`${fmt.grey('⧗')} input: ${fmt.bold(input)}`);
155-
console.log(formatted.join('\n'));
156-
}
157-
158-
if (report.errors.length > 0) {
159-
const error = new Error(formatted[formatted.length - 1]);
160-
error.type = pkg.name;
161-
throw error;
162-
}
163-
console.log('');
164-
})
144+
const reports = await Promise.all(
145+
messages.map(message => lint(message, loaded.rules, opts))
165146
);
147+
148+
return reports.map(report => {
149+
const formatted = format(report, {color: flags.color});
150+
const input =
151+
report.errors.length > 0
152+
? `\n${report.input}\n`
153+
: report.input.split('\n')[0];
154+
155+
if (!flags.quiet) {
156+
console.log(`${fmt.grey('⧗')} input: ${fmt.bold(input)}`);
157+
console.log(formatted.join('\n'));
158+
}
159+
160+
if (report.errors.length > 0) {
161+
const error = new Error(formatted[formatted.length - 1]);
162+
error.type = pkg.name;
163+
throw error;
164+
}
165+
console.log('');
166+
return '';
167+
});
166168
}
167169

168170
function checkFromStdin(input, flags) {
@@ -199,7 +201,7 @@ function getEditValue(flags) {
199201
}
200202
return process.env[flags.env];
201203
}
202-
const edit = flags.edit;
204+
const {edit} = flags;
203205
// If the edit flag is set but empty (i.e '-e') we default
204206
// to .git/COMMIT_EDITMSG
205207
if (edit === '') {

0 commit comments

Comments
 (0)