File tree Expand file tree Collapse file tree 4 files changed +43
-0
lines changed
Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,16 @@ $ core-validate-commit <sha>
1919
2020# validate since <sha>
2121$ git rev-list < sha> ..HEAD | xargs core-validate-commit
22+
23+ # list all rules
24+ $ core-validate-commit --list
25+ fixes-url enforce format of Fixes URLs
26+ line-length enforce max length of lines in commit body
27+ metadata-end enforce that metadata is at the end of commit messages
28+ pr-url enforce PR-URL
29+ reviewers enforce having reviewers
30+ subsystem enforce subsystem validity
31+ title-length enforce max length of commit title
2232```
2333
2434## Test
Original file line number Diff line number Diff line change @@ -13,17 +13,20 @@ const pretty = require('../lib/format-pretty')
1313const formatTap = require ( '../lib/format-tap' )
1414const Validator = require ( '../lib' )
1515const Tap = require ( '../lib/tap' )
16+ const utils = require ( '../lib/utils' )
1617const knownOpts = { help : Boolean
1718 , version : Boolean
1819 , 'validate-metadata' : Boolean
1920 , tap : Boolean
2021 , out : path
22+ , list : Boolean
2123 }
2224const shortHand = { h : [ '--help' ]
2325 , v : [ '--version' ]
2426 , V : [ '--validate-metadata' ]
2527 , t : [ '--tap' ]
2628 , o : [ '--out' ]
29+ , l : [ '--list' ]
2730 }
2831
2932const parsed = nopt ( knownOpts , shortHand )
@@ -79,6 +82,19 @@ function loadPatch(uri, cb) {
7982
8083const v = new Validator ( parsed )
8184
85+ if ( parsed . list ) {
86+ const ruleNames = Array . from ( v . rules . keys ( ) )
87+ const max = ruleNames . reduce ( ( m , item ) => {
88+ if ( item . length > m ) m = item . length
89+ return m
90+ } , 0 )
91+
92+ for ( const rule of v . rules . values ( ) ) {
93+ utils . describeRule ( rule , max )
94+ }
95+ return
96+ }
97+
8298if ( parsed . tap ) {
8399 const stream = parsed . out
84100 ? fs . createWriteStream ( parsed . out )
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ core-validate-commit - Validate the commit message for a particular commit in no
77 -v, --version show version
88 -V, --validate-metadata validate PR-URL and revieweres (on by default)
99 -t, --tap output in tap format
10+ -l, --list list rules and their descriptions
1011
1112 examples:
1213 Validate a single sha:
Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ exports.rightPad = function rightPad(str, max) {
1717 return str
1818}
1919
20+ exports . leftPad = function leftPad ( str , max ) {
21+ const diff = max - str . length + 1
22+ if ( diff > 0 ) {
23+ return `${ ' ' . repeat ( diff ) } ${ str } `
24+ }
25+ return str
26+ }
27+
2028exports . header = ( sha , status ) => {
2129 switch ( status ) {
2230 case 'skip' :
@@ -29,3 +37,11 @@ exports.header = (sha, status) => {
2937 return `${ X } ${ chalk . underline ( sha ) } `
3038 }
3139}
40+
41+ exports . describeRule = function describeRule ( rule , max = 20 ) {
42+ if ( rule . meta && rule . meta . description ) {
43+ const desc = rule . meta . description
44+ const title = exports . leftPad ( rule . id , max )
45+ console . log ( ' %s %s' , chalk . red ( title ) , chalk . dim ( desc ) )
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments