Skip to content

Commit 3fc89f4

Browse files
byCedricmarionebl
authored andcommitted
refactor(cli): create issue report and implement new formatter
1 parent 1ecf097 commit 3fc89f4

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

@commitlint/cli/src/cli.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ require('babel-polyfill'); // eslint-disable-line import/no-unassigned-import
44
const load = require('@commitlint/load');
55
const lint = require('@commitlint/lint');
66
const read = require('@commitlint/read');
7-
const chalk = require('chalk');
87
const meow = require('meow');
98
const merge = require('lodash.merge');
109
const pick = require('lodash.pick');
@@ -118,7 +117,6 @@ async function main(options) {
118117
const fromStdin = checkFromStdin(raw, flags);
119118

120119
const range = pick(flags, 'edit', 'from', 'to');
121-
const fmt = new chalk.constructor({enabled: flags.color});
122120

123121
const input = await (fromStdin ? stdin() : read(range, {cwd: flags.cwd}));
124122

@@ -147,30 +145,32 @@ async function main(options) {
147145
opts.parserOpts.commentChar = '#';
148146
}
149147

150-
const reports = await Promise.all(
148+
const results = await Promise.all(
151149
messages.map(message => lint(message, loaded.rules, opts))
152150
);
153151

154-
return reports.map(report => {
155-
const formatted = format(report, {color: flags.color});
156-
const input =
157-
report.errors.length > 0
158-
? `\n${report.input}\n`
159-
: report.input.split('\n')[0];
152+
const report = results.reduce(
153+
(info, result) => {
154+
info.valid = result.valid ? info.valid : false;
155+
info.errorCount += result.errors.length;
156+
info.warningCount += result.warnings.length;
157+
info.results.push(result);
160158

161-
if (!flags.quiet) {
162-
console.log(`${fmt.grey('⧗')} input: ${fmt.bold(input)}`);
163-
console.log(formatted.join('\n'));
159+
return info;
160+
},
161+
{
162+
valid: true,
163+
errorCount: 0,
164+
warningCount: 0,
165+
results: []
164166
}
167+
);
165168

166-
if (report.errors.length > 0) {
167-
const error = new Error(formatted[formatted.length - 1]);
168-
error.type = pkg.name;
169-
throw error;
170-
}
171-
console.log('');
172-
return '';
173-
});
169+
if (!flags.quiet) {
170+
process.stdout.write(format(report, flags));
171+
}
172+
173+
process.exit(report.errorCount === 0 ? 0 : 1);
174174
}
175175

176176
function checkFromStdin(input, flags) {

0 commit comments

Comments
 (0)