@@ -4,7 +4,6 @@ require('babel-polyfill'); // eslint-disable-line import/no-unassigned-import
4
4
const load = require ( '@commitlint/load' ) ;
5
5
const lint = require ( '@commitlint/lint' ) ;
6
6
const read = require ( '@commitlint/read' ) ;
7
- const chalk = require ( 'chalk' ) ;
8
7
const meow = require ( 'meow' ) ;
9
8
const merge = require ( 'lodash.merge' ) ;
10
9
const pick = require ( 'lodash.pick' ) ;
@@ -118,7 +117,6 @@ async function main(options) {
118
117
const fromStdin = checkFromStdin ( raw , flags ) ;
119
118
120
119
const range = pick ( flags , 'edit' , 'from' , 'to' ) ;
121
- const fmt = new chalk . constructor ( { enabled : flags . color } ) ;
122
120
123
121
const input = await ( fromStdin ? stdin ( ) : read ( range , { cwd : flags . cwd } ) ) ;
124
122
@@ -147,30 +145,32 @@ async function main(options) {
147
145
opts . parserOpts . commentChar = '#' ;
148
146
}
149
147
150
- const reports = await Promise . all (
148
+ const results = await Promise . all (
151
149
messages . map ( message => lint ( message , loaded . rules , opts ) )
152
150
) ;
153
151
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 ) ;
160
158
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 : [ ]
164
166
}
167
+ ) ;
165
168
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 ) ;
174
174
}
175
175
176
176
function checkFromStdin ( input , flags ) {
0 commit comments