@@ -31,6 +31,7 @@ program.on('--help', function(){
3131 console . log ( ' htmlhint www/test.html' ) ;
3232 console . log ( ' htmlhint www/**/*.xhtml' ) ;
3333 console . log ( ' htmlhint www/**/*.{htm,html}' ) ;
34+ console . log ( ' cat test.html | htmlhint stdin' ) ;
3435 console . log ( ' htmlhint --list' ) ;
3536 console . log ( ' htmlhint --rules tag-pair,id-class-value=underline test.html' ) ;
3637 console . log ( ' htmlhint --config .htmlhintrc test.html' ) ;
@@ -190,36 +191,37 @@ function hintAllFiles(target, options, onFinised){
190191 // hint queue
191192 var hintQueue = async . queue ( function ( filepath , next ) {
192193 var startTime = new Date ( ) . getTime ( ) ;
193- var messages = hintFile ( filepath , ruleset ) ;
194- var spendTime = new Date ( ) . getTime ( ) - startTime ;
195- var hintCount = messages . length ;
196- if ( hintCount > 0 ) {
197- formatter . emit ( 'file' , {
198- 'file' : filepath ,
199- 'messages' : messages ,
200- 'time' : spendTime
201- } ) ;
202- arrTargetMessages . push ( {
203- 'file' : filepath ,
204- 'messages' : messages ,
205- 'time' : spendTime
206- } ) ;
207- targetHintFileCount ++ ;
208- targetHintCount += hintCount ;
194+ if ( filepath === 'stdin' ) {
195+ hintStdin ( ruleset , hintNext ) ;
196+ }
197+ else {
198+ var messages = hintFile ( filepath , ruleset ) ;
199+ hintNext ( messages ) ;
200+ }
201+ function hintNext ( messages ) {
202+ var spendTime = new Date ( ) . getTime ( ) - startTime ;
203+ var hintCount = messages . length ;
204+ if ( hintCount > 0 ) {
205+ formatter . emit ( 'file' , {
206+ 'file' : filepath ,
207+ 'messages' : messages ,
208+ 'time' : spendTime
209+ } ) ;
210+ arrTargetMessages . push ( {
211+ 'file' : filepath ,
212+ 'messages' : messages ,
213+ 'time' : spendTime
214+ } ) ;
215+ targetHintFileCount ++ ;
216+ targetHintCount += hintCount ;
217+ }
218+ targetFileCount ++ ;
219+ setImmediate ( next ) ;
209220 }
210- targetFileCount ++ ;
211- setImmediate ( next ) ;
212221 } , 10 ) ;
213222 // start hint
214223 var isWalkDone = false ;
215224 var isHintDone = true ;
216- walkPath ( globInfo , function ( filepath ) {
217- isHintDone = false ;
218- hintQueue . push ( filepath ) ;
219- } , function ( ) {
220- isWalkDone = true ;
221- checkAllHinted ( ) ;
222- } ) ;
223225 hintQueue . drain = function ( ) {
224226 isHintDone = true ;
225227 checkAllHinted ( ) ;
@@ -234,6 +236,19 @@ function hintAllFiles(target, options, onFinised){
234236 } ) ;
235237 }
236238 }
239+ if ( target === 'stdin' ) {
240+ isWalkDone = true ;
241+ hintQueue . push ( target ) ;
242+ }
243+ else {
244+ walkPath ( globInfo , function ( filepath ) {
245+ isHintDone = false ;
246+ hintQueue . push ( filepath ) ;
247+ } , function ( ) {
248+ isWalkDone = true ;
249+ checkAllHinted ( ) ;
250+ } ) ;
251+ }
237252}
238253
239254// split target to base & glob
@@ -337,3 +352,18 @@ function hintFile(filepath, ruleset){
337352 catch ( e ) { }
338353 return HTMLHint . verify ( content , ruleset ) ;
339354}
355+
356+ // hint stdin
357+ function hintStdin ( ruleset , callback ) {
358+ process . stdin . setEncoding ( 'utf8' ) ;
359+ var buffers = [ ] ;
360+ process . stdin . on ( 'data' , function ( text ) {
361+ buffers . push ( text ) ;
362+ } ) ;
363+
364+ process . stdin . on ( 'end' , function ( ) {
365+ var content = buffers . join ( '' ) ;
366+ var messages = HTMLHint . verify ( content , ruleset ) ;
367+ callback ( messages ) ;
368+ } ) ;
369+ }
0 commit comments