@@ -53,27 +53,59 @@ function processInputData(input) {
5353 process . stderr . write ( e . message ) ;
5454 process . exit ( 1 ) ;
5555 } ) . then ( output => {
56- process . stdout . write ( output ) ;
57- process . exit ( 0 ) ;
56+ if ( ! output . length ) {
57+ process . exit ( 0 ) ;
58+ } else {
59+ process . stdout . write ( output ) ;
60+ process . exit ( 1 ) ;
61+ }
5862 } ) ;
5963}
6064
6165function processSTDIN ( ) {
6266 getInputData . then ( processInputData ) ;
6367}
6468
65- function processFiles ( files , config ) {
69+ function processFiles ( files ) {
70+ let anyErrorsFound = false ;
71+
6672 const promises = files . map ( file => {
67- return comb . lintPath ( file ) ;
73+ return comb . lintPath ( file ) . then ( errors => {
74+ if ( ! errors . length ) {
75+ return ;
76+ }
77+
78+ anyErrorsFound = true ;
79+ const message = formatErrors ( file , errors ) ;
80+ process . stdout . write ( message ) ;
81+ } ) ;
6882 } ) ;
6983
7084 Promise . all ( promises ) . catch ( error => {
7185 process . stderr . write ( error . message ) ;
7286 process . exit ( 1 ) ;
73- } ) . then ( function ( c ) {
74- console . log ( c ) ;
75- process . exit ( 0 ) ;
87+ } ) . then ( function ( ) {
88+ if ( anyErrorsFound ) {
89+ process . exit ( 1 ) ;
90+ } else {
91+ process . exit ( 0 ) ;
92+ }
93+ } ) ;
94+ }
95+
96+ function formatErrors ( fileName , errors ) {
97+ let message = [ ] ;
98+
99+ errors . forEach ( error => {
100+ message . push (
101+ error . message + ' at ' + fileName + ':' + error . line ,
102+ error . context ,
103+ '' ,
104+ ''
105+ ) ;
76106 } ) ;
107+
108+ return message . join ( '\n' ) ;
77109}
78110
79111function getOptions ( ) {
@@ -157,7 +189,7 @@ var config = getConfig(options);
157189comb . configure ( config ) ;
158190
159191if ( process . stdin . isTTY ) {
160- processFiles ( options . _ , config ) ;
192+ processFiles ( options . _ ) ;
161193} else {
162194 processSTDIN ( ) ;
163195}
0 commit comments