@@ -229,6 +229,11 @@ var printUsage = function (asCommand, standalone) {
229229 ctx . write ( " ignore=<file> path to the file containing file patterns to ignore. Patterns are defined\n" ) ;
230230 ctx . write ( " per line. Each line represent a glob pattern. Empty lines and lines starting\n" ) ;
231231 ctx . write ( " with a hash sign (#) are ignored.\n" ) ;
232+ ctx . write ( " serr=<scope> scope of syntax errors to be reported. By default all errors are reported.\n" ) ;
233+ ctx . write ( " serr=none reports no syntax errors\n" ) ;
234+ ctx . write ( " serr=all reports all syntax errors\n" ) ;
235+ ctx . write ( " serr=ext reports syntax errors for files defined with ext option\n" ) ;
236+ ctx . write ( " serr=mext reports syntax errors for files defined with mext option\n" ) ;
232237 ctx . write ( " --help, -h, print this help screen and exit\n" )
233238 ctx . write ( " --version, -v print version and exit\n" )
234239 if ( ! asCommand && ! standalone ) {
@@ -302,6 +307,7 @@ var processAndValidateArgs = function (args) {
302307 var arboriPath = null ;
303308 var ignorePath = null ;
304309 var ignoreMatcher = null ;
310+ var serr = null ;
305311 var files = [ ] ;
306312 var result = function ( valid ) {
307313 return {
@@ -312,6 +318,7 @@ var processAndValidateArgs = function (args) {
312318 xmlPath : xmlPath ,
313319 arboriPath : arboriPath ,
314320 ignoreMatcher : ignoreMatcher ,
321+ serr : serr ,
315322 valid : valid
316323 } ;
317324 }
@@ -371,6 +378,9 @@ var processAndValidateArgs = function (args) {
371378 if ( typeof configJson . ignore !== 'undefined' ) {
372379 ignorePath = configJson . ignore ;
373380 }
381+ if ( typeof configJson . serr !== 'undefined' ) {
382+ serr = configJson . serr . toLowerCase ( ) ;
383+ }
374384 if ( typeof configJson . files !== 'undefined' ) {
375385 if ( ! Array . isArray ( configJson . files ) ) {
376386 ctx . write ( "files in " + rootPath + " is not an array.\n\n" ) ;
@@ -431,6 +441,10 @@ var processAndValidateArgs = function (args) {
431441 ignorePath = args [ i ] . substring ( 7 ) ;
432442 continue ;
433443 }
444+ if ( args [ i ] . toLowerCase ( ) . indexOf ( "serr=" ) === 0 ) {
445+ serr = args [ i ] . substring ( 5 ) . toLowerCase ( ) ;
446+ continue ;
447+ }
434448 ctx . write ( "invalid argument " + args [ i ] + ".\n\n" ) ;
435449 return result ( false ) ;
436450 }
@@ -482,6 +496,14 @@ var processAndValidateArgs = function (args) {
482496 }
483497 ignoreMatcher = createIgnoreMatcher ( ignorePath ) ;
484498 }
499+ if ( serr == null ) {
500+ serr = "all" ;
501+ } else {
502+ if ( serr !== "all" && serr !== "none" && serr !== "ext" && serr != "mext" ) {
503+ ctx . write ( "invalid scope '" + serr + "' for serr. Valid are: all, none, ext, mext.\n\n" ) ;
504+ return result ( false ) ;
505+ }
506+ }
485507 return result ( true ) ;
486508}
487509
@@ -511,17 +533,26 @@ var isMarkdownFile = function (file, markdownExtensions) {
511533 return false ;
512534}
513535
514- var formatMarkdownFile = function ( file , formatter ) {
536+ var formatMarkdownFile = function ( file , formatter , serr ) {
515537 var original = readFile ( file )
516538 var p = javaPattern . compile ( "(```\\s*sql\\s*\\n)(.+?)(\\n```)" , javaPattern . DOTALL ) ;
517539 var m = p . matcher ( original ) ;
518540 var result = "" ;
519541 var pos = 0 ;
542+ var consoleOutput = false ;
543+ if ( serr == "all" || serr == "mext" ) {
544+ consoleOutput = true ;
545+ }
546+ var sqlBlock = 0 ;
520547 while ( m . find ( ) ) {
548+ sqlBlock ++ ;
549+ ctx . write ( "#" + sqlBlock + "... " ) ;
521550 result += original . substring ( pos , m . end ( 1 ) ) ;
522- if ( hasParseErrors ( m . group ( 2 ) , false ) ) {
551+ if ( hasParseErrors ( m . group ( 2 ) , consoleOutput ) ) {
552+ ctx . write ( "skipped... " )
523553 result += original . substring ( m . start ( 2 ) , m . end ( 3 ) ) ;
524554 } else {
555+ ctx . write ( "done... " )
525556 result += formatter . format ( m . group ( 2 ) ) ;
526557 result += original . substring ( m . end ( 2 ) , m . end ( 3 ) ) ;
527558 }
@@ -546,24 +577,28 @@ var getLineSeparator = function (input) {
546577 return lineSep ;
547578}
548579
549- var formatFile = function ( file , formatter ) {
580+ var formatFile = function ( file , formatter , serr ) {
550581 var original = readFile ( file )
551- if ( hasParseErrors ( original , true ) ) {
582+ var consoleOutput = false ;
583+ if ( serr == "all" || serr == "ext" ) {
584+ consoleOutput = true ;
585+ }
586+ if ( hasParseErrors ( original , consoleOutput ) ) {
552587 ctx . write ( "skipped.\n" ) ;
553588 } else {
554589 writeFile ( file , formatter . format ( original ) + getLineSeparator ( original ) ) ;
555590 ctx . write ( "done.\n" ) ;
556591 }
557592}
558593
559- var formatFiles = function ( files , formatter , markdownExtensions ) {
594+ var formatFiles = function ( files , formatter , markdownExtensions , serr ) {
560595 for ( var i = 0 ; i < files . length ; i ++ ) {
561596 ctx . write ( "Formatting file " + ( i + 1 ) + " of " + files . length + ": " + files [ i ] . toString ( ) + "... " ) ;
562597 ctx . getOutputStream ( ) . flush ( ) ;
563598 if ( isMarkdownFile ( files [ i ] , markdownExtensions ) ) {
564- formatMarkdownFile ( files [ i ] , formatter ) ;
599+ formatMarkdownFile ( files [ i ] , formatter , serr ) ;
565600 } else {
566- formatFile ( files [ i ] , formatter ) ;
601+ formatFile ( files [ i ] , formatter , serr ) ;
567602 }
568603 ctx . getOutputStream ( ) . flush ( ) ;
569604 }
@@ -617,7 +652,7 @@ var run = function (args) {
617652 } else {
618653 files = getFiles ( options . rootPath , options . extensions , options . ignoreMatcher ) ;
619654 }
620- formatFiles ( files , formatter , options . markdownExtensions ) ;
655+ formatFiles ( files , formatter , options . markdownExtensions , options . serr ) ;
621656 }
622657 }
623658 }
0 commit comments