@@ -14,7 +14,8 @@ class BranchNameLint {
1414 msgBranchDisallowed : 'Pushing to "%s" is not allowed, use git-flow.' ,
1515 msgPrefixNotAllowed : 'Branch prefix "%s" is not allowed.' ,
1616 msgPrefixSuggestion : 'Instead of "%s" try "%s".' ,
17- msgSeperatorRequired : 'Branch "%s" must contain a seperator "%s".'
17+ msgSeperatorRequired : 'Branch "%s" must contain a seperator "%s".' ,
18+ msgDoesNotMatchRegex : 'Does not match the regex given'
1819 } ;
1920
2021 this . options = Object . assign ( defaultOptions , options ) ;
@@ -23,6 +24,15 @@ class BranchNameLint {
2324 this . SUCCESS_CODE = 0 ;
2425 }
2526
27+ validateWithRegex ( ) {
28+ if ( this . options . regex ) {
29+ const REGEX = new RegExp ( this . options . regex ) ;
30+ return REGEX . test ( this . branch ) ;
31+ }
32+
33+ return true ;
34+ }
35+
2636 doValidation ( ) {
2737 const parts = this . branch . split ( this . options . seperator ) ;
2838 const prefix = parts [ 0 ] . toLowerCase ( ) ;
@@ -47,6 +57,10 @@ class BranchNameLint {
4757 return this . error ( this . options . msgSeperatorRequired , this . branch , this . options . seperator ) ;
4858 }
4959
60+ if ( ! this . validateWithRegex ( ) ) {
61+ return this . error ( this . options . msgBranchDisallowed , this . branch , this . options . regex ) ;
62+ }
63+
5064 if ( this . options . prefixes . includes ( prefix ) === false ) {
5165 if ( this . options . suggestions [ prefix ] ) {
5266 this . error (
0 commit comments