@@ -43,24 +43,20 @@ if (options.detect) {
4343var config = getConfig ( ) ;
4444comb . configure ( config ) ;
4545
46- if ( options . fix && process . stdin . isTTY ) {
46+ if ( process . stdin . isTTY ) {
4747 processFiles ( options . _ ) ;
48- } else if ( options . fix ) {
49- processSTDIN ( ) ;
50- } else if ( process . stdin . isTTY ) {
51- lintFiles ( options . _ ) ;
5248} else {
53- lintSTDIN ( ) ;
49+ processSTDIN ( ) ;
5450}
5551
5652
5753function getOptions ( ) {
5854 var parserOptions = {
59- boolean : [ 'help' , 'fix ' , 'verbose' ] ,
55+ boolean : [ 'help' , 'lint ' , 'verbose' ] ,
6056 alias : {
6157 config : 'c' ,
6258 detect : 'd' ,
63- fix : 'f ' ,
59+ lint : 'l ' ,
6460 help : 'h' ,
6561 verbose : 'v'
6662 }
@@ -82,8 +78,8 @@ function displayHelp() {
8278 ' Path to configuration file.' ,
8379 ' -d, --detect' ,
8480 ' Run the tool in detect mode, returning detected options.' ,
85- ' -f , --fix ' ,
86- ' Run the tool in fixer mode, modifying files when possible .' ,
81+ ' -l , --lint ' ,
82+ ' Run the tool in linter mode, without modifying files.' ,
8783 ' -h, --help' ,
8884 ' Display help message.' ,
8985 ' -v, --verbose' ,
@@ -119,6 +115,7 @@ function getConfig() {
119115
120116 applyTemplate ( config ) ;
121117 if ( options . verbose ) config . verbose = options . verbose ;
118+ if ( options . lint ) config . lint = options . lint ;
122119
123120 return config ;
124121}
@@ -155,15 +152,21 @@ function processFiles(files) {
155152 return a + b ;
156153 } , 0 ) ;
157154
158- if ( config . verbose ) {
155+ var changed = options . lint ? 0 : tbchanged ;
156+
157+ if ( options . verbose ) {
159158 let message = [
160159 `${ c . length } file${ c . length === 1 ? '' : 's' } processed` ,
161- `${ tbchanged } file${ tbchanged === 1 ? '' : 's' } fixed` ,
160+ `${ changed } file${ changed === 1 ? '' : 's' } fixed` ,
162161 ''
163162 ] . join ( '\n' ) ;
164163 process . stdout . write ( message ) ;
165164 }
166165
166+ if ( options . lint && tbchanged ) {
167+ process . exit ( 1 ) ;
168+ }
169+
167170 process . exit ( 0 ) ;
168171 } ) ;
169172}
@@ -181,63 +184,3 @@ function processInputData(input) {
181184 process . exit ( 0 ) ;
182185 } ) ;
183186}
184-
185- function lintFiles ( files ) {
186- let anyErrorsFound = false ;
187-
188- const promises = files . map ( file => {
189- return comb . lintPath ( file ) . then ( errors => {
190- if ( ! errors . length ) {
191- return ;
192- }
193-
194- anyErrorsFound = true ;
195- const message = formatErrors ( file , errors ) ;
196- process . stdout . write ( message ) ;
197- } ) ;
198- } ) ;
199-
200- Promise . all ( promises ) . catch ( error => {
201- process . stderr . write ( error . message ) ;
202- process . exit ( 1 ) ;
203- } ) . then ( function ( ) {
204- if ( anyErrorsFound ) {
205- process . exit ( 1 ) ;
206- } else {
207- process . exit ( 0 ) ;
208- }
209- } ) ;
210- }
211-
212- function formatErrors ( fileName , errors ) {
213- let message = [ ] ;
214-
215- errors . forEach ( error => {
216- message . push (
217- error . message + ' at ' + fileName + ':' + error . line ,
218- error . context ,
219- '' ,
220- ''
221- ) ;
222- } ) ;
223-
224- return message . join ( '\n' ) ;
225- }
226-
227- function lintSTDIN ( ) {
228- getInputData . then ( lintInputData ) ;
229- }
230-
231- function lintInputData ( input ) {
232- comb . lintString ( input ) . catch ( e => {
233- process . stderr . write ( e . message ) ;
234- process . exit ( 1 ) ;
235- } ) . then ( output => {
236- if ( ! output . length ) {
237- process . exit ( 0 ) ;
238- } else {
239- process . stdout . write ( output ) ;
240- process . exit ( 1 ) ;
241- }
242- } ) ;
243- }
0 commit comments