@@ -6,7 +6,6 @@ const exec = require('child_process').exec
66const fs = require ( 'fs' )
77const http = require ( 'http' )
88const https = require ( 'https' )
9- const url = require ( 'url' )
109const nopt = require ( 'nopt' )
1110const path = require ( 'path' )
1211const pretty = require ( '../lib/format-pretty' )
@@ -16,42 +15,42 @@ const Tap = require('../lib/tap')
1615const utils = require ( '../lib/utils' )
1716const subsystem = require ( '../lib/rules/subsystem' )
1817const knownOpts = {
19- help : Boolean
20- , version : Boolean
21- , 'validate-metadata' : Boolean
22- , tap : Boolean
23- , out : path
24- , list : Boolean
25- , 'list-subsystems' : Boolean
18+ help : Boolean ,
19+ version : Boolean ,
20+ 'validate-metadata' : Boolean ,
21+ tap : Boolean ,
22+ out : path ,
23+ list : Boolean ,
24+ 'list-subsystems' : Boolean
2625}
2726const shortHand = {
28- h : [ '--help' ]
29- , v : [ '--version' ]
30- , V : [ '--validate-metadata' ]
31- , t : [ '--tap' ]
32- , o : [ '--out' ]
33- , l : [ '--list' ]
34- , ls : [ '--list-subsystems' ]
27+ h : [ '--help' ] ,
28+ v : [ '--version' ] ,
29+ V : [ '--validate-metadata' ] ,
30+ t : [ '--tap' ] ,
31+ o : [ '--out' ] ,
32+ l : [ '--list' ] ,
33+ ls : [ '--list-subsystems' ]
3534}
3635
3736const parsed = nopt ( knownOpts , shortHand )
3837const usage = require ( 'help' ) ( )
3938
4039if ( parsed . help ) {
41- return usage ( )
40+ usage ( )
41+ process . exit ( 0 )
4242}
4343
4444if ( parsed . version ) {
4545 console . log ( 'core-validate-commit' , 'v' + require ( '../package' ) . version )
46- return
46+ process . exit ( 0 )
4747}
4848
4949const args = parsed . argv . remain
50- if ( ! args . length )
51- args . push ( 'HEAD' )
50+ if ( ! args . length ) { args . push ( 'HEAD' ) }
5251
53- function load ( sha , cb ) {
54- const parsed = url . parse ( sha )
52+ function load ( sha , cb ) {
53+ const parsed = new URL ( sha )
5554 if ( parsed . protocol ) {
5655 return loadPatch ( parsed , cb )
5756 }
@@ -62,7 +61,7 @@ function load(sha, cb) {
6261 } )
6362}
6463
65- function loadPatch ( uri , cb ) {
64+ function loadPatch ( uri , cb ) {
6665 let h = http
6766 if ( ~ uri . protocol . indexOf ( 'https' ) ) {
6867 h = https
@@ -91,7 +90,7 @@ const v = new Validator(parsed)
9190
9291if ( parsed [ 'list-subsystems' ] ) {
9392 utils . describeSubsystem ( subsystem . defaults . subsystems . sort ( ) )
94- return
93+ process . exit ( 0 )
9594}
9695
9796if ( parsed . list ) {
@@ -104,15 +103,15 @@ if (parsed.list) {
104103 for ( const rule of v . rules . values ( ) ) {
105104 utils . describeRule ( rule , max )
106105 }
107- return
106+ process . exit ( 0 )
108107}
109108
110109if ( parsed . tap ) {
111110 const tap = new Tap ( )
112111 tap . pipe ( process . stdout )
113112 if ( parsed . out ) tap . pipe ( fs . createWriteStream ( parsed . out ) )
114113 let count = 0
115- let total = args . length
114+ const total = args . length
116115
117116 v . on ( 'commit' , ( c ) => {
118117 count ++
@@ -121,41 +120,39 @@ if (parsed.tap) {
121120 if ( count === total ) {
122121 setImmediate ( ( ) => {
123122 tap . end ( )
124- if ( tap . status === 'fail' )
125- process . exitCode = 1
123+ if ( tap . status === 'fail' ) { process . exitCode = 1 }
126124 } )
127125 }
128126 } )
129127
130- function run ( ) {
131- if ( ! args . length ) return
132- const sha = args . shift ( )
133- load ( sha , ( err , data ) => {
134- if ( err ) throw err
135- v . lint ( data )
136- run ( )
137- } )
138- }
139-
140- run ( )
141-
128+ tapRun ( )
142129} else {
143130 v . on ( 'commit' , ( c ) => {
144131 pretty ( c . commit , c . messages , v )
145- run ( )
132+ commitRun ( )
146133 } )
147134
148- function run ( ) {
149- if ( ! args . length ) {
150- process . exitCode = v . errors
151- return
152- }
153- const sha = args . shift ( )
154- load ( sha , ( err , data ) => {
155- if ( err ) throw err
156- v . lint ( data )
157- } )
158- }
135+ commitRun ( )
136+ }
137+
138+ function tapRun ( ) {
139+ if ( ! args . length ) return
140+ const sha = args . shift ( )
141+ load ( sha , ( err , data ) => {
142+ if ( err ) throw err
143+ v . lint ( data )
144+ tapRun ( )
145+ } )
146+ }
159147
160- run ( )
148+ function commitRun ( ) {
149+ if ( ! args . length ) {
150+ process . exitCode = v . errors
151+ return
152+ }
153+ const sha = args . shift ( )
154+ load ( sha , ( err , data ) => {
155+ if ( err ) throw err
156+ v . lint ( data )
157+ } )
161158}
0 commit comments